Esempio n. 1
0
    def getQuestionFromDatabase(self):
        db = Database()
        conn = db.getConnection()
        cursor = conn.cursor()

        # get data from db
        cursor.execute('SELECT * FROM Questions')
        records = cursor.fetchall()
Esempio n. 2
0
    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()
Esempio n. 3
0
    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()
Esempio n. 4
0
    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()
Esempio n. 5
0
    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
Esempio n. 6
0
    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