예제 #1
0
def does_user_exist(cursor: CursorBase, username: str) -> bool:
    """
    Return whether or not a user with the given username exists
    in the database, using the given cursor
    """
    cursor.execute(SELECT_USER, (username, ))
    cursor.fetchall()
    return cursor.rowcount > 0
예제 #2
0
	def populate_courses_table_with_new_courses(cursor: CursorBase) -> None:
		cursor.execute(
			"SELECT %s, %s FROM %s" %
			(TBLCol.course_number, TBLCol.course_name, TBL.Courses)
		)
		courses_already_in_db = cursor.fetchall()
		course_to_add_list = [
			course for course in mit_courses
			if course not in courses_already_in_db
		]
		if len(course_to_add_list) > 0:
			course_population_data = (
				TBL.Courses,
				TBLCol.course_number,
				TBLCol.course_name,
				",".join(
					["(" + ",".join(
						[quote(s) for s in course_row]
					) + ")" for course_row in course_to_add_list]
				),
			)
			cursor.execute(
				"INSERT INTO %s (%s, %s) VALUES %s;" %
				course_population_data
			)
예제 #3
0
def get_departments(cursor: CursorBase) -> list:
    """
    Get a list of the names of all departments in the database, using
    the given cursor.
    """
    cursor.execute(DEPARTMENTS_QUERY)
    return [d[0] for d in cursor.fetchall()]
예제 #4
0
def get_usernames(cursor: CursorBase) -> list:
    """
    Get a list of the usernames of all users in the database, using
    the given cursor.
    """
    cursor.execute(USERNAMES_QUERY)
    return [d[0] for d in cursor.fetchall()]
예제 #5
0
def get_semesters(cursor: CursorBase) -> list:
    """
    Get a list of all the semesters in the database, using the
    given cursor.

    The returned list is a list of tuples representing the 
    season and cal_year of a semester (in that order).
    """
    cursor.execute(SEMESTERS_QUERY)
    return cursor.fetchall()
예제 #6
0
def get_savings(cursor: CursorBase, cfr: tuple) -> list:
    """
    Get a list of the salary savings entries associated with the given cfr,
    using the given cursor.

    The returned value is a list of tuples with fields corresponding
    to SAL_FIELDS

    cfr should be a tuple with the following fields (in this order):
    dept_name, semester, cal_year, [date_initial], [date_revised],
    revision_num, [cfr_submitter], [dean_committed]
    (fields in brackets are not used, but this order is still expected)
    """
    cfr_data = (cfr[0], cfr[1], cfr[2], cfr[5])
    cursor.execute(SELECT_SAVINGS, cfr_data)
    return cursor.fetchall()
예제 #7
0
def get_course_approvals(cursor: CursorBase, cfr: tuple) -> list:
    """
    Get a list of the approval information for the courses associated with the
    given cfr, using the given cursor.

    The returned value is a list of tuples with fields corresponding to the
    'approver' and 'commitment_code_ columns in the database.

    cfr should be a tuple with the following fields (in this order):
    dept_name, semester, cal_year, [date_initial], [date_revised],
    revision_num, [cfr_submitter], [dean_committed]
    (fields in brackets are not used, but this order is still expected)
    """
    cfr_data = (cfr[0], cfr[1], cfr[2], cfr[5])
    cursor.execute(SELECT_COURSE_APPROVALS, cfr_data)
    return cursor.fetchall()
예제 #8
0
def get_all_revisions_for_semester(cursor: CursorBase, dept_name: str,
                                   semester: tuple) -> list:
    """
    Get all the cfr revisions for the given department in the given semester,
    using the given cursor.

    semester should be a tuple containing the season and
    cal_year of the semester (in that order).

    The returned value is a list of tuples with the following fields (in this order):
    dept_name, semester, cal_year, date_initial, date_revised,
    revision_num, cfr_submitter, dean_committed
    """
    query = (dept_name, semester[0], semester[1])
    cursor.execute(SELECT_REVISIONS, query)
    return cursor.fetchall()
예제 #9
0
def retorna_quadrados(current_cursor: CursorBase, log: bool = False) -> Union[Tuple, int]:
    """Retorna todos os quadrados que estão no banco de dados.

    Args:
        current_cursor (int): Cursor aberto que executará as queries.
        log (bool, optional): Ativa e desativa o logging. Default é False.

    Returns:
        Union[List[Tuple], int]: Todos os quadrados que estão no banco ou 0 caso
            alguma coisa tenha dado errado.

    """
    try:
        query = f"SELECT * FROM Quadrado"
        current_cursor.execute(query)
        columns = [column[0] for column in current_cursor.description]
        rows = [dict(zip(columns, row)) for row in current_cursor.fetchall()]
        if log:
            print(current_cursor.rowcount, "Quadrados retornados")
        return rows
    except Exception as e:
        if log:
            print("Não retornou os quadrados", e)
        return 0
예제 #10
0
def retorna_jogadores(current_cursor: CursorBase,
                      log: bool = False) -> List[Tuple]:
    """Retorna todos os jogadores que estão no banco de dados.

    Args:
        current_cursor (CursorBase): Cursor aberto que executará as queries.
        log (bool, optional): Ativa e desativa o logging. Default é False.

    Returns:
        List[Tuple]: Todos os jogadores que estão no banco de dados.

    """
    try:
        query = f"SELECT * FROM Jogador"
        current_cursor.execute(query)
        columns = [column[0] for column in current_cursor.description]
        rows = [dict(zip(columns, row)) for row in current_cursor.fetchall()]
        if log:
            print(current_cursor.rowcount, "Jogadores retornados")
        return rows
    except Exception as e:
        if log:
            print("Não retornou os jogadores", e)
        return 0