即使事务失败,也保留变量的特定值 [英] Retain a particular value of a variable even when transaction fails

查看:69
本文介绍了即使事务失败,也保留变量的特定值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说,我有一个名为JohnDoe = 0的全局int变量。我有一个执行许多操作的事务,包括将我的JohnDoe变量更新为5.现在,当事务成功时,所有值都被提交,JohnDoe现在变为5但是如果我的事务失败,所有值都会回滚,JohnDoe变为0.即使事务失败,我是否可以单独提交此变量的值?即使事务失败,我也希望将JohnDoe的值保留为5,尽管所有其他操作都应该回滚?有什么方法可以实现这个目的吗?

Say, I have a global int variable called JohnDoe = 0. I have a transaction which performs many actions, including updating my JohnDoe variable to 5. Now, when the transaction succeeds, all the values are committed and JohnDoe now becomes 5. But if my transaction fails, all the values are rolled back and JohnDoe becomes 0. Is there any way I can commit the value of this variable alone even if the transaction fails ? Even if the transaction fails, I want to retain the value of JohnDoe as 5, though all other actions should be rolled back ? Is there any way I can accomplish this ?

推荐答案

否 - 当发生回滚时,它旨在恢复数据库的原始状态,以便它是处于可控状态。它不能留下一些改变而有些不改变,因为它不知道哪些位对你很重要而哪些不重要。



最好的你可以do是在事务之外更改变量,或者嵌套事务,以便您可以独立于外部回滚内部变量。
No - when a roll-back occurs, it is intended to restore the original state of the DB so that it is left in a manageable condition. It can't leave some bits changed and some not, because it doesn't know what bits are important to you and which aren't.

The best you can do is change your variable outside the transaction, or nest transactions so that you can roll back the inner one independently of the outer.


这篇关于即使事务失败,也保留变量的特定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆