Ejemplo n.º 1
0
    def find_all(self):
        """
        returns all Student from database, or empty list if table in datbase is empty.

        :return: list() of model.Student.Student or empty list
        """
        ret = []
        self.connect()
        try:
            sql = """select * from {0}""".format(self.tablename)
            self.cursor.execute(sql)
            rows = self.cursor.fetchall()
            for row in rows:
                ret.append(StudentRowMapper().map_from_row(row))
        except Exception as err:
            print(err)
        finally:
            self.disconnect()

        return ret
Ejemplo n.º 2
0
    def find_by_id(self, enrolmentNumber):
        """
        returns Student from database with enrolmentNumber == enrolmentNumber or None 
        if no Student was found in database.

        :param enrolmentNumber: int 
        :return: model.Student.Student or None  
        """
        ret = None
        self.connect()
        try:
            sql = """select * from {0} where enrolmentNumber = {1}""".format(
                self.tablename, enrolmentNumber)
            self.cursor.execute(sql)
            row = self.cursor.fetchone()
            ret = StudentRowMapper().map_from_row(row)
        except Exception as err:
            print(err)
        finally:
            self.disconnect()

        return ret