CP363: Assignment 1 - Fall 2022

Due 11:00 PM, Monday, February 20, 2023

General Assignment Notes

When writing and submitting your assignments follow these requirements:

Marks will be deducted from any questions where these requirements are not met.


WARNING

Follow the assignment instructions to the letter (e.g. name the function module functions.py), as this assignment is auto-graded. If your Eclipse project is not defined correctly, the auto-grading fails, and your assignment will be given a mark of 0.

Links

Pages of use for this assignment:

These questions use the DCRIS database.

These functions return lists of tuples containing the results of the various database calls. How you display these results is up to you. Do not call print from within the functions. Do not close the database from within the functions. It is the responsibility of whatever opens the database to close the database.

  1. Write and test the following function:

    
    def get_broad(cursor, broadId=None):
        """
        -------------------------------------------------------
        Queries the broad table.
        Use: rows = get_broad(cursor)
        Use: rows = get_broad(cursor, broadId=v)
        -------------------------------------------------------
        Parameters:
            cursor - a database cursor (cursor)
            broadId - a broad ID (int)
        Returns:
            rows - (list of broad table data)
                if broadId is not None:
                    rows matching broadId
                else:
                    the entire broad table
                Sorted by broad description
        -------------------------------------------------------
        """
    

    Add this function to the PyDev module functions.py. Test it from .

    This function uses a Python feature known as named arguments. Function arguments may be given default values. If the function is called without the argument, that argument is given its default value. These arguments can be listed in any order by using their names.

    In this function the default value None is given to the parameter broadId by the definition line:

    
    def get_broad(cursor, broadId=None):
    
    

    The documentation for this function show two versions of Use::

    
        Use: rows = get_broad(cursor)
    

    instructs Python to accept the first parameter cursor as passed in, and sets broadId to its default value None. The second version:

    
        Use: rows = get_broad(cursor, broadId=v)
    

    instructs Python to accept the first parameter as above, and then assign the value v to the broadId parameter.

    Your code clearly must decide what to do when broadId is None and otherwise.

    Note that you have used named arguments to functions before, although we didn't call them that. Two examples:

    
    print(value, end="")
    fv = open(filename, encoding="utf-8")
    

  2. Write and test the following function:

    
    def get_publications(cursor, memberId=None, pubPubType=None):
        """
        -------------------------------------------------------
        Queries the pub table.
        Use: rows = get_publications(cursor)
        Use: rows = get_publications(cursor, memberId=v1)
        Use: rows = get_publications(cursor, pubPubType=v2)
        Use: rows = get_publications(cursor, memberId=v1, pubPubType=v2)
        -------------------------------------------------------
        Parameters:
            cursor - a database cursor (cursor)
            memberId - a member ID number (int)
            pubPubType - a publication type (str)
        Returns:
            rows - (list of pub table data)
                if memberId and/or pubPubType are not None:
                    rows matching memberId and/or pubPubType
                else:
                    the entire pub table
                Sorted by publication title
        -------------------------------------------------------
        """
    

    Add this function to the PyDev module functions.py. Test it from .


  3. Write and test the following function:

    
    def get_member_broad(cursor, memberId=None, broadId=None):
        """
        -------------------------------------------------------
        Queries the vMemberBroad view.
        Use: rows = get_member_broad(cursor)
        Use: rows = get_member_broad(cursor, memberId=v1)
        Use: rows = get_member_broad(cursor, broadId=v2)
        Use: rows = get_member_broad(cursor, memberId=v1, broadId=v2)
        -------------------------------------------------------
        Parameters:
            cursor - a database cursor (cursor)
            memberId - a member ID number (int)
            broadId - a broad ID number (int)
        Returns:
            rows - (list of vMemberBroad view data)
                if memberId and/or broadId are not None:
                    rows matching memberId and/or broadId
                else:
                    the entire vMemberBroad view
                Sorted by member last name, first name, and broad description
        -------------------------------------------------------
        """
    

    Add this function to the PyDev module functions.py. Test it from .


  4. Write and test the following function:

    
    def get_expertises(cursor, broad=None, narrow=None):
        """
        -------------------------------------------------------
        Queries the vBroadNarrow view.
        Use: rows = get_expertises(cursor)
        Use: rows = get_expertises(cursor, broad=v1)
        Use: rows = get_expertises(cursor, narrow=v2)
        Use: rows = get_expertises(cursor, broad=v1, narrow=v2)
        -------------------------------------------------------
        Parameters:
            cursor - a database cursor (cursor)
            broad - a partial broad expertise description (str)
            narrow - a partial narrow expertise description (str)
        Returns:
            rows - (list of vBroadNarrow view data)
                if broad and/or narrow are not None:
                    rows containing broad and/or narrow
                else:
                    the entire vBroadNarrow view
                Sorted by broad description, narrow broad description
        -------------------------------------------------------
        """
    

    Add this function to the PyDev module functions.py. Test it from .