def addQuizToDatabase(self): db = Database() conn = db.getConnection() # insert one value: var should be a tuple conn.execute('INSERT INTO Quizes(QuizName) VALUES(?)', (self.quizName,)) conn.commit() db.closeConnection()
def deleteQuiz(self, val): id = val db = Database() conn = db.getConnection() cursor = conn.cursor() cursor.execute('DELETE FROM Quizes WHERE Id = ?', (id,)) conn.commit() db.closeConnection()
def addQuestionToDatabase(self): db = Database() conn = db.getConnection() # insert one value: var should be a tuple conn.execute('INSERT INTO Questions(QuizId, Question, Solution, Answer1, Answer2, Answer3, Answer4, Timer, Points) VALUES' '(?,?,?,?,?,?,?,?,?)', (self.quizId, self.question, self.solution, self.answer1, self.answer2, self.answer3, self.answer4, self.timer, self.points)) conn.commit() db.closeConnection()
def getIdFromQuizName(self, val): quizName = val db = Database() conn = db.getConnection() cursor = conn.cursor() # get data from db # WHERE: you need to pass the var as a tuple cursor.execute('SELECT Id FROM Quizes WHERE QuizName = ?', (quizName,)) records = cursor.fetchone() db.closeConnection() return records
def createQuizWithQuestions(self, val): # CREATE LIST OF ALL QUESTION FROM SAME QUIZ ID quizId = val db = Database() conn = db.getConnection() cursor = conn.cursor() # get data from db cursor.execute('SELECT * FROM Questions WHERE QuizId = ?', (quizId,)) records = cursor.fetchall() questionsDictionary = [] i = 0 for i in range(len(records)): q = records[i] # options options = {} if q[4]: options["option1"] = q[4] if q[5]: options["option2"] = q[5] if q[6]: options["option3"] = q[6] if q[7]: options["option4"] = q[7] question = { "id": str(q[0]), "question": q[2], "solution": q[3], "options": options, "time": q[8], "score": q[9] } questionsDictionary.append(question) i = i+1 db.closeConnection() return questionsDictionary