Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to insert a new user into the Room database.
Android Kotlin
suspend fun addUser(user: User) {
userDao.[1](user)
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using method names like 'add' or 'saveUser' which are not standard in Room DAO.
Confusing insert with update or delete methods.
✗ Incorrect
The correct Room DAO method to insert a record is 'insert'.
2fill in blank
mediumComplete the code to update an existing user in the Room database.
Android Kotlin
suspend fun updateUser(user: User) {
userDao.[1](user)
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-standard method names like 'modify' or 'edit'.
Mixing up update with insert or delete.
✗ Incorrect
The correct Room DAO method to update a record is 'update'.
3fill in blank
hardFix the error in the delete function to remove a user from the Room database.
Android Kotlin
suspend fun deleteUser(user: User) {
userDao.[1](user)
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using method names like 'remove' or 'erase' which are not standard in Room DAO.
Confusing delete with insert or update.
✗ Incorrect
The correct Room DAO method to delete a record is 'delete'.
4fill in blank
hardFill both blanks to write a query that selects all users ordered by their name.
Android Kotlin
@Query("SELECT * FROM users ORDER BY [1] [2]") suspend fun getAllUsers(): List<User>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'id' instead of 'name' for ordering by name.
Using 'DESC' when ascending order is intended.
✗ Incorrect
To order users by name ascending, use 'name' and 'ASC'.
5fill in blank
hardFill all three blanks to write a query that selects users with age greater than 18 ordered by age descending.
Android Kotlin
@Query("SELECT * FROM users WHERE [1] [2] 18 ORDER BY [3] DESC") suspend fun getAdultUsers(): List<User>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong column names like 'name' for filtering by age.
Using '<' instead of '>' for filtering adults.
✗ Incorrect
The query filters users where age > 18 and orders by age descending.