database programming and since we expect the number of matching records to be smallwe fetch them all at once into sequence of sequences if there is more than one matching record and few enough to displaywe print the records with number beside each one so that the user can choose the one they want in much the same way as they could in the dvds-dbm py program def list_dvds(db)cursor db cursor(sql ("select dvds titledvds yeardvds duration"directors name from dvdsdirectors "where dvds director_id directors id"start none if dvd_count(dbdisplay_limitstart console get_string("list those starting with "[enter=all]""start"sql +and dvds title like ?sql +order by dvds titleprint(if start is nonecursor execute(sqlelsecursor execute(sql(start "%",)for record in cursorprint("{ [ ]({ [ ]}{ [ ]minutesby { [ ]}formatrecord)to list the details of each dvd we do select query that joins the two tablesadding second element to the where clause if there are more records (returned by our dvd_count(functionthan the display limit we then execute the query and iterate over the results each record is sequence whose fields are those matching the select query def dvd_count(db)cursor db cursor(cursor execute("select count(*from dvds"return cursor fetchone()[ we factored these lines out into separate function because we need them in several different functions we have omitted the code for the list_directors(function since it is structurally very similar to the list_dvds(functiononly simpler because it lists only one field (namedef remove_dvd(db)titleidentity find_dvd(db"remove"if title is none