def forgot_password( email, new_pass, confirm_pass): # Used to change the user password if forgotten if password_check( new_pass, confirm_pass ) is True: # validation for password from remake_register password_store = bcrypt.hashpw(new_pass.encode("utf8"), bcrypt.gensalt()) # changes the password into a hashed value using bcrypt if (student_email(email) is not False and teacher_email(email) is False): # Checks if the email is in the student table and not in the teacher table update_student = ("UPDATE Students SET password=? WHERE email=?") # sql for changing the student password cursor.execute(update_student, [(password_store), (email)]) # executes the sql statement with password_store variable that has the specific email db.commit() # saves changes made return True # refers back to the tkinter page elif (student_email(email) is False and teacher_email(email) is not False): # email must be in teacher table and not student table update_teacher = ("UPDATE Teachers SET password=? WHERE email=?") # sql statement for changing the teacher password cursor.execute(update_teacher, [(password_store), (email)]) # executes the sql statement with password_store variable on the condition of the user that has the email db.commit() # save changes made return True # refers back to the tkinter page else: messagebox.showerror( "Email", "Email doesn't exist either message support or register as you haven't made an account" ) # this is error message shown if student_check and teacher check fails else: pass # no error message is needed here as password_check has its own error messages
def view_info(user, school): global header global result header = ("Forename", "Surname", "Age", "Class") widths = [len(cell) for cell in header] result = "blank" if school is "Student": view = ("SELECT Forename,Surname,Age,Class FROM Students WHERE username = ?") cursor.execute(view, [(user)]) student_check = cursor.fetchone() for i, cell in enumerate(student_check): widths[i] = max(len(str(cell)), widths[i]) formatted_row = ' '.join('{:%d}' % width for width in widths) header = formatted_row.format(*header) result = formatted_row.format(*student_check) return "S" elif school is "Teacher": view = ("SELECT Forename,Surname,Age,Class FROM Teachers WHERE username = ?") cursor.execute(view, [(user)]) teacher_check = cursor.fetchone() for i, cell in enumerate(teacher_check): widths[i] = max(len(str(cell)), widths[i]) formatted_row = ' '.join('{:%d}' % width for width in widths) header = formatted_row.format(*header) result = formatted_row.format(*teacher_check) return "T"
def username_check(username): # function for username vaildation # Checking the length of username is between 6 and 30 chracters if (len(username) >= 6) and (len(username) <= 30): # sql statement for checking existing users # Checks student database for username fetchstudents = ( "SELECT DISTINCT Students.Username from Students WHERE Username = ?" ) # Checkes teacher databaase for username fetchteachers = ( "SELECT DISTINCT Teachers.Username from Teachers WHERE Username = ?" ) cursor.execute( fetchstudents, [(username)]) # executes the above query on the student table cursor1.execute( fetchteachers, [(username)]) # execute the above query on the teacher table checking = cursor.fetchall( ) # stores the result of sql search done on the Student table checking1 = cursor1.fetchall( ) # stores the result of sql search done on the Teacher table if checking or checking1: # if checking or checking1 has values then return tkinter error messagebox.showerror( "Username", "That username has been taken please try another one") else: # if checking and checking 1 is none then return true return True else: #if username isn't in the range then return tkinter error message messagebox.showerror("Username", "Username has to be between 6 and 30 characters")
def end_loop(loop, user, correct, incorrect, score, level, total): if total == 0: # no questions attempted return False else: store_id = get_student(user) # gets the user id using get_student total = len(question_store) # gets the len of question store for total questions attempted if loop is "Pure": # if loop is pure sql = """INSERT INTO pure_results (user_id,level, score, Correct, Incorrect,total_questions, time_stamp) VALUES (?, ?, ?, ?, ?, ?,?) """ # sql for inserting a record into pure_results table cursor.execute( sql, [(store_id), (level), (score), (correct), (incorrect), (total), (current_date)]) # executes the statment with python variales db.commit() # saves changes made to database file question_store.clear() # removes all the values in question_store return True elif loop is "Applied": # if loop is applied sql = """INSERT INTO applied_results (user_id,level, score, Correct, Incorrect,total_questions, time_stamp) VALUES (?, ?, ?, ?, ?, ?,?) """ # sql for inserting a record into applied_results table cursor.execute( sql, [(store_id), (level), (score), (correct), (incorrect), (total), (current_date)]) # executes the statment with python variales db.commit() # saves changes made to database file question_store.clear() # removes all the values in question_store return True
def username_check(username): # function for username vaildation # Checking the length of username is more than 6 charcters if len(username) >= 6: # sql statement for checking existing users # Checks student database for username fetchstudents = ( "SELECT DISTINCT Students.Username from Students WHERE Username = ?" ) # Checkes teacher databaase for username fetchteachers = ( "SELECT DISTINCT Teachers.Username from Teachers WHERE Username = ?" ) cursor.execute( fetchstudents, [(username)]) # executes the above query on the student table cursor1.execute( fetchteachers, [(username)]) # execute the above query on the teacher table checking = cursor.fetchall() # stores the result of sql search checking1 = cursor1.fetchall() if checking or checking1: messagebox.showerror( "Username", "That username has been taken please try another one") else: return True else: messagebox.showerror("Username", "Username has to be 6 or more characters")
def correct_graphs(user_id): dates_pure = [] correct_pure = [] sql_pure = """SELECT time_stamp,SUM(Correct) FROM pure_results WHERE user_id = ? GROUP BY time_stamp""" cursor.execute(sql_pure, [(user_id)]) for a in cursor.fetchall(): dates_pure.append(a[0]) correct_pure.append(a[1]) dates_applied = [] correct_applied = [] sql_applied = """SELECT time_stamp, SUM(Correct) FROM applied_results WHERE user_id = ? GROUP BY time_stamp""" cursor.execute(sql_applied, [(user_id)]) for b in cursor.fetchall(): dates_applied.append(b[0]) correct_applied.append(b[1]) plt.figure(1) plt.subplot(211) plt.plot(dates_pure, correct_pure) plt.ylabel("Questions Correct") plt.xlabel("Dates of Maths Question Attempted") plt.title("Pure Maths Correct Progress") plt.subplot(212) plt.plot(dates_applied, correct_applied, "-g") plt.xlabel("Dates of Maths Question Attempted") plt.ylabel("Questions Correct") plt.title("Applied Maths Correct Progress") plt.tight_layout() plt.show()
def student_email( email ): # checks the email the user entered against the student database find_student = ("SELECT Students.email FROM Students WHERE email = ?") # sql statement checks based on email variable condition cursor.execute(find_student, [(email)]) # execution of sql statement result = cursor.fetchone() # gets one value if result is not None: # checks based on condition that there is values to check db_email = result # sets the value db_email based on result if email == db_email: # checks user input against database value return True # if condition is met it returns true else: return False # if condition not met it returns false
def score_graph(user_id): dates = [] total_score = [] sql = """SELECT time_stamp,SUM(score) total FROM (SELECT time_stamp,score FROM pure_results WHERE user_id = ? UNION ALL SELECT time_stamp,score FROM applied_results WHERE user_id = ?) t GROUP BY time_stamp""" cursor.execute(sql, [(user_id), (user_id)]) for a in cursor.fetchall(): dates.append(a[0]) total_score.append(a[1]) plt.plot(dates, total_score) plt.xlabel("Date") plt.ylabel("Current Score") plt.title("A level Score Progess") plt.show()
def total_graph_incorrect(user_id): dates = [] incorrect = [] sql = """SELECT time_stamp,SUM(Incorrect) total FROM (SELECT time_stamp,Incorrect FROM pure_results WHERE user_id = ? UNION ALL SELECT time_stamp, Incorrect FROM applied_results WHERE user_id = ?) t GROUP BY time_stamp""" cursor.execute(sql, [(user_id), (user_id)]) for a in cursor.fetchall(): dates.append(a[0]) incorrect.append(a[1]) plt.plot(dates, incorrect, label="Incorrect Progess") plt.xlabel("Dates of Maths Question Attempted") plt.ylabel("Incorrect Questions") plt.title("A Level Maths Total Incorrect Progress") plt.show()
def student_check(username, password): # Used for the login function this checks against the username and password the user enters in students table find_user = ("SELECT username,password FROM Students WHERE username = ?") # sql statement for getting the username and password cursor.execute(find_user, [(username)]) #executes the above sql code checking = cursor.fetchone() # fetchs one of the values if checking is not None: # if there are values in check then it goes through this process db_user, db_password = checking # gets username and password stored in the database if (username == db_user) and (bcrypt.checkpw(password.encode("utf8"), db_password) is True): #checks the database username and password against the username and password stored return True # if condition met return true else: return False # if condition not met return False
def graph_total_questions(user_id): dates = [] total_questions = [] sql = """SELECT time_stamp,SUM(total_questions) total FROM (SELECT time_stamp,total_questions FROM pure_results WHERE user_id = ? UNION ALL SELECT time_stamp,total_questions FROM applied_results WHERE user_id = ?) t GROUP BY time_stamp""" cursor.execute(sql, [(user_id), (user_id)]) for a in cursor.fetchall(): dates.append(a[0]) total_questions.append(a[1]) plt.plot(dates, total_questions) plt.xlabel("Dates of Questions Attempted") plt.ylabel("Total Questions Attempted") plt.title("A Level Maths Total Questions Attempted") plt.show()
def register2(username, password, confirm_password, email, var1): # checks whether a existing username with the username enter exists if username_check(username): # ensures the password passes all the vaildations if password_check(password, confirm_password): password_store = bcrypt.hashpw(password.encode("utf8"), bcrypt.gensalt()) if email_check(email): # ensures the email passes the vaildation if var1 == 1: # inserts one whole record into student table insert_student = ( "INSERT INTO Students(Forename,Surname,Age,Class,Gender,Username,Password,Email) VALUES (?, ?, ?, ?, ?, ?, ?, ?)" ) cursor.execute(insert_student, [(shared_data["firstname"]), (shared_data["surname"]), (shared_data["age"]), (shared_data["Class"]), (shared_data["gender"]), (username), (password_store), (email)]) send_email(email, username) elif var1 == 2: # inserts one whole record into the teacher table insert_teacher = ( "INSERT INTO Teachers(Forename,Surname,Age,Class,Gender,Username,Password,Email) VALUES (?, ?, ?, ?, ?, ?, ?, ?)" ) cursor.execute(insert_teacher, [(shared_data["firstname"]), (shared_data["surname"]), (shared_data["age"]), (shared_data["Class"]), (shared_data["gender"]), (username), (password_store), (email)]) send_email(email, username) db.commit() # saves the changes to the database file return True else: return False else: return False else: return False
def score_graph(user_id): dates = [] # two lists one for dates the other for total questions total_score = [] # sql that combines score (along with the date connected to it) # from both tables into one value and groups the dates together # hence returning it back in order using the user_id sql = """SELECT time_stamp,SUM(score) total FROM (SELECT time_stamp,score FROM pure_results WHERE user_id = ? UNION ALL SELECT time_stamp,score FROM applied_results WHERE user_id = ?) t GROUP BY time_stamp""" cursor.execute(sql, [(user_id), (user_id)]) # executes sql statement for a in cursor.fetchall(): # appends the data to the two lists dates.append(a[0]) total_score.append(a[1]) plt.figure(1) # creates the figure for the graph to be plot plt.plot(dates, total_score) # plots the data on the figure plt.xlabel("Date") # labels the x axis plt.ylabel("Current Score") # labels the y axis plt.title("A level Score Progess") # gives the graph a title plt.figure(1).autofmt_xdate() # formats the x axis to prevent overlap plt.show() # shows the graph
def correct_graphs(user_id): dates_pure = [] # lists that stores dates and correct from pure results correct_pure = [] # sql for getting the dates and correct from table pure results in the db file # using the user_id sql_pure = """SELECT time_stamp,SUM(Correct) FROM pure_results WHERE user_id = ? GROUP BY time_stamp""" cursor.execute(sql_pure, [(user_id)]) # executing the sql for a in cursor.fetchall(): # storing the result in the pure lists dates_pure.append(a[0]) correct_pure.append(a[1]) dates_applied = [] # list that stores dates and correct from applied result correct_applied = [] # sql for getting the dates and correct from table applied results # in the db file using the user_id sql_applied = """SELECT time_stamp, SUM(Correct) FROM applied_results WHERE user_id = ? GROUP BY time_stamp""" cursor.execute(sql_applied, [(user_id)]) # executing the sql for b in cursor.fetchall(): dates_applied.append(b[0]) correct_applied.append(b[1]) # storing the result the applied lists plt.figure(1) # creates the figure for the graph to be plot plt.subplot(211) # creates a subplot for the pure graph plt.plot(dates_pure,correct_pure) # plots the pure values on one subplot plt.ylabel("Questions Correct") # labels the y axis plt.xlabel("Dates of Maths Question Attempted") # labels the x axis plt.title("Pure Maths Correct Progress") # puts a title on the graph plt.subplot(212) # creates another subplot for applied graph plt.plot(dates_applied, correct_applied, "-g") #plots the applied values on the other subplot and sets the line colour green plt.xlabel("Dates of Maths Question Attempted") # labels the x axis plt.ylabel("Questions Correct") # labels the y axis plt.title("Applied Maths Correct Progress") # puts a title on the graph plt.tight_layout() # changes the layout to be tight plt.show() # shows the graphs made
def forgot_password( email, new_pass, confirm_pass): # Used to change the user password if forgotten if (student_email(email) is not False and teacher_email(email) is False): if password_check( new_pass, confirm_pass ) is True: # validation for password from remake_register password_store = bcrypt.hashpw( new_pass.encode("utf8"), bcrypt.gensalt()) # hashes the new password update_student = ("UPDATE Students SET password=? WHERE email=?") # updates the password based on the user email and it being a student cursor.execute( update_student, [(password_store), (email)]) # performs the update on the Student table db.commit() # saves changes made return True # refers back to the tkinter page elif (student_email(email) is False and teacher_email(email) is not False): if password_check( new_pass, confirm_pass ) is True: # validation for password from remake_register password_store = bcrypt.hashpw( new_pass.encode("utf8"), bcrypt.gensalt()) # hashes the new password update_student = ("UPDATE Teachers SET password=? WHERE email=?") # updates the password based on the user email and it being a teacher cursor.execute(update_student, [(password_store), (email)]) # performs the update on the Teacher table db.commit() # saves changes made return True # refers back to the tkinter page else: # if either condition is met then it returns an tkinter error message messagebox.showerror( "Email", "Email doesn't exist either message support or register as you haven't made an account" ) # this is error message
def total_graph_correct(user_id): dates = [] # Two lists one for dates the other for correct correct = [] # Sql that combines correct (along with the date connected to it) from both tables into # one value and groups the dates together hence returning it back in order # using the user_id sql = """SELECT time_stamp,SUM(Correct) total FROM (SELECT time_stamp,Correct FROM pure_results WHERE user_id = ? UNION ALL SELECT time_stamp, Correct FROM applied_results WHERE user_id = ?) t GROUP BY time_stamp""" cursor.execute(sql, [(user_id), (user_id)]) # executes th sql statement for a in cursor.fetchall(): # appends the results found to the two lists dates.append(a[0]) correct.append(a[1]) plt.plot(dates, correct, label="Total Correct Progress") # plots the data # and sets a label on it plt.xlabel("Dates of Maths Question Attempted") # labels the x axis plt.ylabel("Questions Correct") # labels the y axis plt.title("A Level Maths Total Correct Progress") # gives the graph a title plt.figure(1).autofmt_xdate() # formats the x axis to prevent overlap on the figure plt.show() # shows the graph
def incorrect_graphs(user_id): dates_pure = [] # four lists 2 for pure and 2 for applied incorrect_pure = [] dates_applied = [] incorrect_applied = [] # Sql that perform the same task but on different tables pure_results and applied_results # using the user_id getting the incorrect values along with there respective date sql_pure = """SELECT time_stamp,SUM(Incorrect) FROM pure_results WHERE user_id = ? GROUP BY time_stamp""" sql_applied = """SELECT time_stamp, SUM(Incorrect) FROM applied_results WHERE user_id = ? GROUP BY time_stamp""" cursor.execute(sql_pure, [(user_id)]) #executes the pure statement for a in cursor.fetchall(): # appends all the values to the two pure lists dates_pure.append(a[0]) incorrect_pure.append(a[1]) cursor.execute(sql_applied, [(user_id)]) # executes the applied statement for b in cursor.fetchall(): # appends all the value to the two applied lists dates_applied.append(b[0]) incorrect_applied.append(b[1]) plt.figure(1) # creates the figure for the graph to be plot plt.subplot(211) # creates a subplot for the pure graph plt.plot(dates_pure,incorrect_pure) # plots the pure values on one subplot plt.ylabel("Questions Incorrect") # labels the y axis plt.xlabel("Dates of Maths Question Attempted") # labels the x axis plt.title("Pure Maths Incorrect Progress") # puts a title on the graph plt.subplot(212) # creates another subplot for applied graph plt.plot(dates_applied, incorrect_applied, "-g") #plots the applied values on the other subplot and sets the line colour green plt.xlabel("Dates of Maths Question Attempted") # labels the x axis plt.ylabel("Questions Incorrect") # labels the y axis plt.title("Applied Maths Incorrect Progress") # puts a title on the graph plt.tight_layout()# changes the layout to be tight plt.show() # shows the graphs made
def graph_total_questions(user_id): dates = [] # two lists one for dates the other for total questions total_questions = [] # sql that combines total_question (along with the date connected to it) # from both tables into one value and groups the dates together # hence returning it back in order using the user_id sql = """SELECT time_stamp,SUM(total_questions) total FROM (SELECT time_stamp,total_questions FROM pure_results WHERE user_id = ? UNION ALL SELECT time_stamp,total_questions FROM applied_results WHERE user_id = ?) t GROUP BY time_stamp""" cursor.execute(sql, [(user_id), (user_id)]) # executes the sql for a in cursor.fetchall(): # appends the data found to the two lists dates.append(a[0]) total_questions.append(a[1]) plt.figure(1) # creates the figure for the graph to be plot plt.plot(dates, total_questions) # plots the data on the figure plt.xlabel("Dates of Questions Attempted") # labels the x axis plt.ylabel("Total Questions Attempted") # labels the y axis plt.title("A Level Maths Total Questions Attempted") # gives the graph a title plt.figure(1).autofmt_xdate()# formats the x axis to prevent overlap plt.show() # shows the graph
def get_surname( user_id ): # gets the user surname using the user id from the table Students sql_surname = """SELECT Surname FROM Students WHERE ID = ?""" cursor.execute(sql_surname, [(user_id)]) return cursor.fetchone()[0] # returns the surname of the user
"""CREATE TABLE IF NOT EXISTS Students(ID INTEGER PRIMARY KEY, Forename VARCHAR(30), Surname VARCHAR(30) , Age INTEGER , class VARCHAR (3), Gender VARCHAR (30) , Username VARCHAR(30),Password VARCHAR(80), Email VARCHAR(30))""" ) create_teacher_table = ( """CREATE TABLE IF NOT EXISTS Teachers( ID INTEGER PRIMARY KEY, Forename VARCHAR(30) , Surname VARCHAR(30) , Age INTEGER , Class VARCHAR (3) , Gender VARCHAR (30), Username VARCHAR(30), Password VARCHAR(80), Email VARCHAR(30))""" ) # Sql statment to create the table where the user information will be stored cursor.execute(create_student_table) # executes the sql statement # Sql statment to create the table where the user information will be stored cursor.execute(create_teacher_table) # executes the sql statement db.commit() # saves changes made to the sql file def get_forename( user_id ): # gets the user forename using the user id from the table Students sql_forename = """SELECT Forename FROM Students WHERE ID = ?""" cursor.execute(sql_forename, [(user_id)]) return cursor.fetchone()[0] # returns the forename of the user def get_surname(
def make_question(question_text, type, level, answer): # function for making questions # sql for inserting a question into maths questions insert_question = ("""INSERT INTO maths_questions (test_type, test_level, question, answer) VALUES (?, ?, ?, ?) """) answer_string = str(answer) # makes sure answer is in string form match = re.match( "[\w,\s,.]*$", question_text ) # ensures a space and alphanumeric characters in question text if match is not None and (len(question_text) >= 50): # question text has to be longer than 50 if type is 1: # when type is 1 question type is pure question_type = "Pure" if level is 1: # when level is 1 question type is AS if answer_string.isalnum( ) is True: # ensures question meets alphanumeric validation question_level = "AS" cursor.execute( insert_question, [ (question_type ), # executes inserts question into db (question_level), (question_text), (str(answer)) ]) db.commit() # saves changes made and returns true return True else: # error message when answer doesn't meet alpha-numeric validation messagebox.showerror( "Answer", "Answer cannot be left blank and no spaces in answer") elif level is 2: # when level is 2 question type is A2 if answer_string.isalnum( ) is True: # ensures question meets alphanumeric validation question_level = "A2" cursor.execute( insert_question, [ (question_type ), # executes insert question into db (question_level), (question_text), (str(answer)) ]) db.commit() # saves changes made and returns true return True else: # error message when answer doesn't meet alpha-numeric validation messagebox.showerror( "Answer", "Answer cannot be left blank and no spaces in answer") else: # level can only be 1 or 2 if not then return error message messagebox.showerror("Level", "Level cannot be left blank") elif type is 2: # when type is 2 then question type is applied question_type = "Applied" if level is 1: # when level is 1 question type is AS if answer_string.isalnum( ) is True: # ensures question meets alphanumeric validation question_level = "AS" cursor.execute( insert_question, [ (question_type ), # executes insert question into db (question_level), (question_text), (str(answer)) ]) db.commit() # saves changes made and returns true return True else: # error message when answer doesn't meet alpha-numeric validation messagebox.showerror( "Answer", "Answer cannot be left blank and no spaces in answer") elif level is 2: if answer_string.isalnum( ) is True: # error message when answer doesn't meet alpha-numeric validation question_level = "A2" cursor.execute( insert_question, [ (question_type ), # executes insert question into db (question_level), (question_text), (str(answer)) ]) db.commit() # saves changes made and returns true return True else: # error message when answer doesn't meet alpha-numeric validation messagebox.showerror( "Answer", "Answer cannot be left blank and no spaces in answer") else: # when level is not 1 or 2 then return error message messagebox.showerror("Level", "Level cannot be left blank") else: # when type is not 1 or 2 then return error message messagebox.showerror("Type", "Type cannot be left blank") else: # when question doesn't meet the length requirement or regex expression return error message messagebox.showerror( "Question", "Question cannot be left blank and make a reasonable question")
def make_question(question_text, type, level, answer): answer_string = str(answer) match = re.match("[\w,\s,.]*$", question_text) if match is not None and (len(question_text) >= 50): if type is 1: question_type = "Pure" if level is 1: if answer_string.isalnum() is True: question_level = "AS" insert_question = ( """INSERT INTO maths_questions(test_type, test_level, question,answer) VALUES (?, ?, ?, ?) """) cursor.execute(insert_question, [(question_type), (question_level), (question_text), (str(answer))]) db.commit() return True else: messagebox.showerror( "Answer", "Answer cannot be left blank and no spaces in answer") elif level is 2: if answer_string.isalnum() is True: question_level = "A2" insert_question = ( """INSERT INTO maths_questions(test_type, test_level, question, answer) VALUES (?, ?, ?, ?) """) cursor.execute(insert_question, [(question_type), (question_level), (question_text), (str(answer))]) db.commit() return True else: messagebox.showerror( "Answer", "Answer cannot be left blank and no spaces in answer") else: messagebox.showerror("Level", "Level cannot be left blank") elif type is 2: question_type = "Applied" if level is 1: if answer_string.isalnum() is True: question_level = "AS" insert_question = ( """INSERT INTO maths_questions(test_type, test_level, question, answer) VALUES (?, ?, ?, ?) """) cursor.execute(insert_question, [(question_type), (question_level), (question_text), (str(answer))]) db.commit() return True else: messagebox.showerror( "Answer", "Answer cannot be left blank and no spaces in answer") elif level is 2: if answer_string.isalnum() is True: question_level = "A2" insert_question = ( """INSERT INTO maths_questions(test_type, test_level, question, answer) VALUES (?, ?, ?, ?) """) cursor.execute(insert_question, [(question_type), (question_level), (question_text), (str(answer))]) db.commit() return True else: messagebox.showerror( "Answer", "Answer cannot be left blank and no spaces in answer") else: messagebox.showerror("Level", "Level cannot be left blank") else: messagebox.showerror("Type", "Type cannot be left blank") else: messagebox.showerror( "Question", "Question cannot be left blank and make a reasonable question")
def get_students(): sql = """ SELECT ID, Forename, Surname, Age, class, gender FROM students """ cursor.execute(sql) result = cursor.fetchall() return result
def get_student(username): # uses a parameter username sql = "SELECT ID FROM Students WHERE username = ? " # sql for searching for the ID connected to the username cursor.execute(sql, [(username)]) # execution of search for ID return cursor.fetchone()[0] # returns the value of the id
from tkinter import messagebox import datetime as dt import random import re from create_connection import cursor, cursor1, db current_date = dt.date.today().strftime("%Y-%m-%d") create_pure_table = """CREATE TABLE IF NOT EXISTS pure_results (maths_id INTEGER PRIMARY KEY, user_id INTEGER, level TEXT , score INTEGER , total_questions INTEGER, Correct INTEGER, Incorrect INTEGER, time_stamp DATE, FOREIGN KEY (user_id) REFERENCES Students(ID))""" create_applied_table = """CREATE TABLE IF NOT EXISTS applied_results (maths_id INTEGER PRIMARY KEY, user_id INTEGER, level TEXT , score INTEGER ,total_questions INTEGER, Correct INTEGER, Incorrect INTEGER, time_stamp DATE,FOREIGN KEY (user_id) REFERENCES Students(ID))""" cursor.execute(create_pure_table) cursor.execute(create_applied_table) create_question_table = """CREATE TABLE IF NOT EXISTS maths_questions(question_id INTEGER PRIMARY KEY, test_type TEXT,test_level TEXT, question TEXT, answer TEXT) """ cursor.execute(create_question_table) db.commit() question_store = [] questions = [] question_answers = [] def make_question(question_text, type, level, answer): answer_string = str(answer) match = re.match("[\w,\s,.]*$", question_text) if match is not None and (len(question_text) >= 50):
def get_id_student(username): # function for getting the student id # sql that takes the username and returns ID sql = "SELECT ID FROM Students WHERE username = ?" cursor.execute(sql, [(username)]) # execution of the sql return cursor.fetchone()[0] # returns the integer value of ID
def sort_gender(): sql = """ SELECT ID, Forename, Surname, Age, class, gender FROM students ORDER BY Gender""" cursor.execute(sql) result = cursor.fetchall() return result
def get_id_student(username): sql = "SELECT ID FROM Students WHERE username = ?" cursor.execute(sql, [(username)]) return cursor.fetchone()[0]