0
0
Android Kotlinmobile~10 mins

Room queries (Insert, Update, Delete, Select) in Android Kotlin - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
AinsertUser
BsaveUser
Cinsert
Dadd
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.
2fill in blank
medium

Complete 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'
Aupdate
Bmodify
Cchange
Dedit
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-standard method names like 'modify' or 'edit'.
Mixing up update with insert or delete.
3fill in blank
hard

Fix 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'
Adelete
Bremove
CdeleteUser
Derase
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.
4fill in blank
hard

Fill 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'
Aname
BASC
CDESC
Did
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'id' instead of 'name' for ordering by name.
Using 'DESC' when ascending order is intended.
5fill in blank
hard

Fill 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'
Aage
B>
Dname
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong column names like 'name' for filtering by age.
Using '<' instead of '>' for filtering adults.