使用一个包含数据库操作的结果类

huangapple go评论61阅读模式
英文:

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).

huangapple
  • 本文由 发表于 2023年3月12日 10:59:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/75710833.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定