交易sqlite?在 C# 中 [英] transactional sqlite? in C#

查看:19
本文介绍了交易sqlite?在 C# 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个原型应用程序.现在有些事情失败了,比如插入一个非唯一的列.在这种情况下,我想回滚我所做的一切.我该怎么做?我还注意到在 sqlite 中我需要提交数据,在 C# 中它似乎是自动完成的,这让我怀疑有一个自动回滚选项?

I am writing a prototype application. Right now some things fail such as inserting a non unique column. In this case i would like to rollback everything i have did. How do i do that? I also notice in sqlite i need to commit the data, in C# it seems to do it automatically which makes me suspect there is an automatic rollback option?

推荐答案

回滚:看起来您正在寻找的是命令文本INSERT OR ROLLBACK ..."

Rollback: It looks like what you are looking for is the command text "INSERT OR ROLLBACK ... "

事务:sqlite 会自动将每个命令放入其自己的事务中,除非您特别说明何时开始.TML 在他的回答中更深入地解释了这一部分

Transaction: sqlite automatically puts each command into its own transaction unless you specifically state when to begin. TML explains this portion a bit more in-depth in his answer

显式打开/提交交易的示例是:

example of explicitly opening/committing a transaction is:

using (DbTransaction dbTrans = myDBConnection.BeginTransaction())
{
     using (DbCommand cmd = myDBConnection.CreateCommand())
     {
         ...
     }
     dbTrans.Commit();
}

这篇关于交易sqlite?在 C# 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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