OnConflictStrategy.REPLACE 对更新和插入是否同样有效?
Does OnConflictStrategy.REPLACE work the same for Update and Insert?
我们有以下遗留代码
interface BaseDao<T> {
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertOrReplace(data: T): Single<Long>
@Update(onConflict = OnConflictStrategy.REPLACE)
fun update(data: T): Single<Long>
}
函数会达到相同的结果吗?
虽然我根据我的一般 SQL 知识@Insert(onConflict = OnConflictStrategy.REPLACE)
确定 @Insert(onConflict = OnConflictStrategy.REPLACE)
- 如果找到则替换/更新记录
- 如果找不到则插入记录
如果您编码或省略 OnConflictStrategy.REPLACE
,更新将不会插入未找到的记录(行)。更新只能对按照
存在的行进行操作
It is not an error if the WHERE clause does not evaluate to true for any row in the table - this just means that the UPDATE statement affects zero rows. https://sqlite.org/lang_update.html
我们有以下遗留代码
interface BaseDao<T> {
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertOrReplace(data: T): Single<Long>
@Update(onConflict = OnConflictStrategy.REPLACE)
fun update(data: T): Single<Long>
}
函数会达到相同的结果吗?
虽然我根据我的一般 SQL 知识@Insert(onConflict = OnConflictStrategy.REPLACE)
确定 @Insert(onConflict = OnConflictStrategy.REPLACE)
- 如果找到则替换/更新记录
- 如果找不到则插入记录
如果您编码或省略 OnConflictStrategy.REPLACE
,更新将不会插入未找到的记录(行)。更新只能对按照
It is not an error if the WHERE clause does not evaluate to true for any row in the table - this just means that the UPDATE statement affects zero rows. https://sqlite.org/lang_update.html