sqlite ON CONFLICT ABORT和FAIL之间的区别

sqlite ON CONFLICT ABORT和FAIL之间的区别,第1张

概述从 http://www.sqlite.org/lang_conflict.html起 ABORT When an applicable constraint violation occurs, the ABORT resolution algorithm aborts the current SQL statement with an SQLITE_CONSTRAIT error and bac 从 http://www.sqlite.org/lang_conflict.html起

ABORT
When an applicable constraint violation occurs,the ABORT resolution algorithm aborts the current sql statement with an sqlITE_CONSTRAIT error and backs out any changes made by the current sql statement; but changes caused by prior sql statements within the same transaction are preserved and the transaction remains active. This is the default behavior and the behavior proscribed the sql standard.

FAIL
When an applicable constraint violation occurs,the FAIL resolution algorithm aborts the current sql statement with an sqlITE_CONSTRAINT error. But the FAIL resolution does not back out prior changes of the sql statement that Failed nor does it end the transaction. For example,if an UPDATE statement encountered a constraint violation on the 100th row that it attempts to update,then the first 99 row changes are preserved but changes to rows 100 and beyond never occur.

两者都保留在导致约束违规并且不结束事务的语句之前所做的更改.因此,我认为唯一的区别是FAIL解决方案不允许进行进一步的更改,而ABORT只备份冲突的语句.我做对了吗?

答案很简单:FAIL不会回滚当前语句所做的更改.

考虑这两个表:

CREATE table IF NOT EXISTS constFAIL (num UNIQUE ON CONFliCT FAIL);CREATE table IF NOT EXISTS constABORT (num UNIQUE ON CONFliCT ABORT);INSERT INTO constFAIL VALUES (1),(3),(4),(5),(6),(7),(8),(9),(10);INSERT INTO constABORT VALUES (1),(10);

该声明

UPDATE constABORT SET num=num+1 WHERE num<10

会失败并且什么都不改变.
但是这个声明

UPDATE constFAIL SET num=num+1 WHERE num<10

将更新第一行,然后失败并保持1行更新,因此新值为2,3,4,5,6,7,8,9,10

总结

以上是内存溢出为你收集整理的sqlite ON CONFLICT ABORT和FAIL之间的区别全部内容,希望文章能够帮你解决sqlite ON CONFLICT ABORT和FAIL之间的区别所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/1160478.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-01
下一篇 2022-06-01

发表评论

登录后才能评论

评论列表(0条)

保存