def executeCommand(cur, command, vals, returnValue):
    """
    Function for for executing a command with values and handling exceptions

    :param Psycopg.Cursor cur: cursor object from psycopg2 library
    :param str command: the sql command string
    :param list vals: list of values for the command
    :param bool returnValue: boolean values for if the command returns a value

    :returns: Values returned by the query or None if returnValue is False
    """
    cur.execute(command, vals)

    if returnValue:
        return cur.fetchall()
    else:
        return None