Jai*_*odi -1 sqlite android dao android-sqlite android-room
我们在android中使用Room数据库来存储数据。
现在,在 Dao 类中,我们都执行各种查询,如插入、选择、删除、更新等。
我想知道我们如何知道这些查询执行成功?
即如果我这样做:
appDatabase.userDao().insert(userData)
Run Code Online (Sandbox Code Playgroud)
如何通知用户数据已插入特定表并且操作成功?
是的,有没有可用的工具或插件可以让我们看到 Room 数据库的数据?(我已经用谷歌搜索过它,但对于设备监视器有点困惑)
请指导。
一切都在此处的文档中进行了解释。
我们可以为插入、更新和删除操作返回一个值来确定它是否成功。
@Insert
fun insert(item: ItemEntity): Long // returns row that entity was inserted at or -1 on failure
@Update
fun update(item: ItemEntity): Int // returns the number of rows updated successfully
@Delete
fun delete(item: ItemEntity): Int // returns the number of rows deleted successfully
Run Code Online (Sandbox Code Playgroud)
然后当你进行操作时:
val result = cache.insert(item.toItemEntity())
println("result is $result")
Run Code Online (Sandbox Code Playgroud)
不过,查询似乎没有明显的方法来实现此功能。