Python: The data above is stored in a database table called "sets", with column names matching the field names in the CSV file. The table has been created using this SQL command:
CREATE TABLE IF NOT EXISTS sets (set_num, name, year, theme_id, num_parts)
Define a Python function "getThemeSortedBySet" that accepts both a database cursor and a number representing a theme_id. This function must return a list of the database rows which match the given theme_id, sorted by the set_num of the set. To do this, you will need to define a function that selects the value in the set_num column as the key for sorting.
Assuming that "cur" and "x" are the names of the parameters for the database cursor and theme_id respectively, you can use this call to execute and select the correct rows:
cur.execute('SELECT * FROM sets WHERE theme_id=?', x)
For example, if the sample table given in part A were the whole database, then getThemeSortedBySet(cur, 71) must return:
- ('575-1', 'Coast Guard Station', 1978, 71, 301)
- ('575-2', 'Coast Guard Station (Canadian Edition)', 1978, 71, 284)
- ('6338-1', 'Hurricane Harbor', 1995, 71, 364)
- ('6342-1', 'Beach Rescue Chopper', 1993, 71, 149)
- ('6353-1', 'Coastal Cutter', 1991, 71, 184)
- ('6387-1', 'Coastal Rescue Base', 1989, 71, 375)
- ('6518-1', 'Baja Buggy', 1996, 71, 37)
- ('6697-1', 'Rescue-I Helicopter', 1985, 71, 85)