英文:
Using a result class with database operations
问题
最近我遇到一个项目,其中将向 Room 数据库添加一行的函数封装在一个 Result 类中。我想知道这是否真的有必要以及为什么需要这样做。在什么情况下,数据库插入方法会在运行时出现未知错误。
英文:
Recently I came across a project where a function to add a row into a Room database was wrapped in a Result class. I want to know if this is really necessary and why. When would a database insert method for some unknown reason fail at run time.
答案1
得分: 2
当在运行时由于某种未知原因要插入数据库时。
永远不会。
然而,不谨慎的人可能会被触发器所欺骗。
当然,也有可能是插入操作的结果被收集起来。也就是说,便捷的@Insert将返回已插入行的rowid,如果行无法插入(取决于冲突处理策略),则返回-1。
英文:
> When would a database insert method for some unknown reason at run time.
Never.
However, the un-weary could be fooled by a Trigger.
Of course it could simply be that the result of the insert is being collected. That is that the Convenience @Insert will return the rowid of the inserted row or -1 if the row could not be inserted (depends upon the conflict handling strategy).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论