android_catalogue1-2 Exercise 2: Unique Index or Code Check? ============================================================= Recommended answer: check in code (a query before saving), NOT a unique index. Why not a unique index: - The spec says a duplicate is "a warning, never a block". A unique index makes SQLite reject the insert with an exception, so the user could never deliberately own two copies (a second pressing, a replacement disc, a book bought twice). - Case-insensitive matching on title AND creator would need NOCASE on both columns, and it would apply to the import path in Chapter 10 too, making a restore fail on legitimate data. How the code check works (Chapter 9): before saving, ask the repository whether an item exists with the same title and creator, ignoring case and surrounding spaces. If yes, show a warning dialog with "Add anyway" and "Cancel". An ordinary (non-unique) index on title already helps that query, which is one reason Item has one.