def get_mapping(conn, table):
    """
    Obtain a mapping between app ids and their titles.

    :param conn: The SQLite connection.
    :param table: The table to obtain a mapping for (should be apps, widgets or downloading_apps)

    :return: A tuple with two items.  The first value is a dict containing a mapping between
             the title and (id, uuid, flags) for each item.  The second item contains the maximum
             id of the items found.
    """
    cursor = conn.execute(f'''
        SELECT {table}.item_id, {table}.title, items.uuid, items.flags
        FROM {table}
        JOIN items ON items.rowid = {table}.item_id
    ''')

    mapping = {}
    max_id = 0

    while True:
        # Grab the current row
        row = cursor.fetchone()
        if row is None:
            break

        # Unpack the row and add it to our mapping
        id, title, uuid, flags = row
        mapping[title] = (id, uuid, flags)

        # Obtain the maximum id in this table
        max_id = max(max_id, id)

    return mapping, max_id