Esempio n. 1
0
    def find_by_id(self, id):

        result = None

        cursor = self._cnx.cursor()
        command = "SELECT id, creation_time, name, matriculation_nr, course_abbr FROM student WHERE id={}".format(
            id)
        cursor.execute(command)
        tuples = cursor.fetchall()

        if tuples[0] is not None:
            (id, creation_time, name, matriculation_nr,
             course_abbr) = tuples[0]
            student = Student()
            student.set_id(id)
            student.set_creation_time(creation_time)
            student.set_name(name)
            student.set_matriculation_nr(matriculation_nr)
            student.set_course_abbr(course_abbr)

        result = student

        self._cnx.commit()
        cursor.close()

        return result
Esempio n. 2
0
    def find_by_mail(self, email):

        result = None

        cursor = self._cnx.cursor()
        command = "SELECT * FROM student WHERE email LIKE '%{}%'".format(email)
        cursor.execute(command)
        tuples = cursor.fetchall()

        try:
            (id, creation_time, name, matriculation_nr, course_abbr, email,
             google_user_id) = tuples[0]
            student = Student()
            student.set_id(id)
            student.set_creation_time(creation_time)
            student.set_name(name)
            student.set_matriculation_nr(matriculation_nr)
            student.set_course_abbr(course_abbr)
            student.set_email(email)
            student.set_google_user_id(google_user_id)
            result = student

        except IndexError:

            result = None

        self._cnx.commit()
        cursor.close()

        return result
Esempio n. 3
0
    def find_student_by_course_abbr(self, course_abbr):

        result = None

        cursor = self._cnx.cursor()
        command = "SELECT id, creation_time, name, matriculation_nr, course_abbr FROM student WHERE course_abbr={}".format(
            course_abbr)
        cursor.execute(command)
        tuples = cursor.fetchall()

        try:
            (id, creation_time, name, matriculation_nr,
             course_abbr) = tuples[0]
            student = Student()
            student.set_id(id)
            student.set_creation_time(creation_time)
            student.set_name(name)
            student.set_matriculation_nr(matriculation_nr)
            student.set_course_abbr(course_abbr)
            result = student

        except IndexError:

            result = None

        self._cnx.commit()
        cursor.close()

        return result
    def create_student(self, creation_time, name, matriculation_nr,
                       course_abbr):
        """Einen Studenten  anlegen"""
        student = Student()
        student.set_creation_time(creation_time)
        student.set_name(name)
        student.set_matriculation_nr(matriculation_nr)
        student.set_course_abbr(course_abbr)
        student.set_id(1)

        with StudentMapper() as mapper:
            return mapper.insert(student)
Esempio n. 5
0
    def find_all(self):

        result = []
        cursor = self._cnx.cursor()
        cursor.execute(
            "SELECT id, creation_time, name, matriculation_nr, course_abbr FROM student"
        )
        tuples = cursor.fetchall()

        for (id, creation_time, name, matriculation_nr, course_abbr) in tuples:
            student = Student()
            student.set_id(id)
            student.set_creation_time(creation_time)
            student.set_name(name)
            student.set_matriculation_nr(matriculation_nr)
            student.set_course_abbr(course_abbr)
            result.append(student)

        self._cnx.commit()
        cursor.close()

        return result