简体   繁体   English

后续事务涵盖提交期间的错误

[英]Sequel transaction covers errors during commit

I'm using Sequel to access MySql and SQL Server databases.我正在使用 Sequel 访问 MySql 和 SQL Server 数据库。

Sequel allows me to do transactions like this: Sequel 允许我做这样的交易:

@client = Sequel.connect(config)
@client.transaction do
    @client.execute("DELETE FROM UserGroup WHERE UserId = #{user_id}")
    @client.execute("DELETE FROM User WHERE Id = #{user_id}")
end

So, if something goes wrong with my queries, the transaction will roll back and everything will be ok.因此,如果我的查询出现问题,事务将回滚,一切都会好起来的。

If my queries are OK, but at the moment of the commit something goes wrong on the database and the commit fails, will the Ruby code detect that and fail too?如果我的查询没问题,但在提交时数据库出现问题并且提交失败,Ruby 代码是否会检测到并失败?

Depends on how the database adapter is implemented.取决于数据库适配器的实现方式。 It might throw an exception, which would be different than Sequel::Rollback .它可能会抛出一个异常,这与Sequel::Rollback不同。 Therefore, it won't be caught by the transaction method and would bubble up to your code.因此,它不会被transaction方法捕获,并且会冒泡到您的代码中。

But normally, problems occur during the operations within the transaction, and not during the COMMIT itself.但通常,问题发生在事务内的操作期间,而不是在 COMMIT 本身期间。 Normally you should not worry about it.通常你不应该担心它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM