Challenge 3: A Query with a WHERE Clause — Solution @Dao interface NoteDao { @Query("SELECT * FROM notes ORDER BY id DESC") fun getAllNotes(): Flow> @Insert suspend fun insert(note: Note) @Query("SELECT * FROM notes WHERE title LIKE :query") fun searchNotesByTitle(query: String): Flow> } // Usage example (in a ViewModel): // searchNotesByTitle("%grocery%") -- the caller supplies the % wildcards // What happens if the parameter name doesn't match the :placeholder name: // Room's annotation processor validates @Query strings against the // method's actual parameters AT COMPILE TIME. If the method signature // were, say, "fun searchNotesByTitle(searchTerm: String)" but the query // still said "WHERE title LIKE :query", the build would FAIL with a // compile error stating that Room cannot find a parameter matching // ":query" — this is caught long before the app ever runs, not // discovered later as a runtime SQL error or silently wrong results. Notes: - The :query syntax in the @Query string binds directly to the query parameter of the same name in the DAO method signature — Room performs this matching (and validates it) during compilation, which is the compile-time SQL checking mentioned earlier in the chapter. - The % wildcard characters are NOT added by Room automatically — the caller is responsible for including them in the string passed in (e.g. "%grocery%" to match anywhere in the title, or "grocery%" to match only titles starting with "grocery"). - Returning Flow> here (rather than a plain List) means search results stay live too — if a note's title changes to newly match or stop matching the search term, the Flow re-emits automatically, the same live-query behavior as getAllNotes().