Exemplo n.º 1
0
    def find_by_user_id(self, user_id):
        """Suchen eines Studenten anhand der User_ID."""

        result = []
        cursor = self._cnx.cursor()
        command = "SELECT * FROM student WHERE user_id like '{}'".format(
            user_id)
        cursor.execute(command)
        tuples = cursor.fetchall()

        for (id, user_id, name, course, matriculation_number, mail, google_id, create_time) \
                in tuples:
            student = Student()
            student.set_id(id)
            student.set_user_id(user_id)
            student.set_name(name)
            student.set_course(course)
            student.set_matriculation_number(matriculation_number)
            student.set_mail(mail)
            student.set_google_id(google_id)
            student.set_create_time(create_time)
            result.append(student)

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

        return result
Exemplo n.º 2
0
    def find_all(self):
        """Auslesen aller Studenten"""

        result = []
        cursor = self._cnx.cursor()
        command = "SELECT * FROM student"
        cursor.execute(command)
        tuples = cursor.fetchall()

        for (id, user_id, name, course, matriculation_number, mail, google_id, create_time) \
                in tuples:
            student = Student()
            student.set_id(id)
            student.set_user_id(user_id)
            student.set_name(name)
            student.set_course(course)
            student.set_matriculation_number(matriculation_number)
            student.set_mail(mail)
            student.set_google_id(google_id)
            student.set_create_time(create_time)
            result.append(student)

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

        return result
Exemplo n.º 3
0
    def find_by_key(self, id):
        """Suchen eines Studenten mit vorgegebener ID"""

        result = []
        cursor = self._cnx.cursor()
        command = "SELECT * FROM student WHERE id like '{}'".format(id)
        cursor.execute(command)
        tuples = cursor.fetchall()

        if len(tuples) != 0:

            for (id, user_id, name, course, matriculation_number, mail, google_id, create_time) \
                    in tuples:
                student = Student()
                student.set_id(id)
                student.set_user_id(user_id)
                student.set_name(name)
                student.set_course(course)
                student.set_matriculation_number(matriculation_number)
                student.set_mail(mail)
                student.set_google_id(google_id)
                student.set_create_time(create_time)
                result.append(student)
                result = student

        else:
            result = None

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

        return result
Exemplo n.º 4
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
Exemplo n.º 5
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
Exemplo n.º 6
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 find_by_id(self, id):
        """Suchen eines Studenten nach der übergebenen ID. 

        :param id Primärschlüsselattribut eines Studenten aus der Datenbank
        :return Student-Objekt, welche mit der ID übereinstimmt,
                None wenn kein Eintrag gefunden wurde
        """
        result = None

        cursor = self._connection.cursor()
        command = "SELECT id, name, email, google_user_id, mat_nr, kuerzel FROM studenten WHERE id='{}'".format(
            id)
        cursor.execute(command)
        tuples = cursor.fetchall()

        try:
            (id, name, email, google_user_id, mat_nr, kuerzel) = tuples[0]
            student = Student()
            student.set_id(id)
            student.set_name(name)
            student.set_email(email)
            student.set_google_user_id(google_user_id)
            student.set_mat_nr(mat_nr)
            student.set_kuerzel(kuerzel)
            result = student
        except IndexError:
            """Der IndexError wird oben beim Zugriff auf tuples[0] auftreten, wenn der vorherige SELECT-Aufruf
            keine Tupel liefert, sondern tuples = cursor.fetchall() eine leere Sequenz zurück gibt."""
            result = None

        self._connection.commit()
        cursor.close()

        return result
    def find_all(self):
        """Auslesen aller Studenten aus der Datenbank

        :return Alle Studenten-Objekte im System
        """

        result = []

        cursor = self._connection.cursor()

        cursor.execute("SELECT * from studenten")
        tuples = cursor.fetchall()

        for (id, name, email, google_user_id, rolle, mat_nr,
             kuerzel) in tuples:
            student = Student()
            student.set_id(id)
            student.set_name(name)
            student.set_email(email)
            student.set_google_user_id(google_user_id)
            student.set_rolle(rolle)
            student.set_mat_nr(mat_nr)
            student.set_kuerzel(kuerzel)
            result.append(student)

        self._connection.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)
    def create_student(self, user_id, name, course, matriculation_number, mail,
                       google_id):
        """Erstellen des Studenten"""

        student = Student()
        student.set_user_id(user_id)
        student.set_name(name)
        student.set_course(course)
        student.set_matriculation_number(matriculation_number)
        student.set_mail(mail)
        student.set_google_id(google_id)
        student.set_id(1)

        with StudentMapper() as mapper:
            return mapper.insert(student)
Exemplo n.º 11
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
from server.bo.Person import Person
from server.bo.Student import Student

p = Person()
p.set_id(1)
p.set_rolle(Person.ROLLE_DOZENT)
p.set_name("Peter Thies")
print(p)

s = Student()
s.set_id(2)
s.set_name("Daria")
print(s)