如何检测我的应用程序是否不进行交易?

发布于 2025-01-22 02:14:13 字数 464 浏览 0 评论 0 原文

mysql python Connector

我正在使用 我从连接池中取一个数据库连接。在所有请求的最后,我提交连接,以确保无意中丢失任何无所事事的交易。但是,我想以自动化的方式找到这些不承担的交易,以便可以在更合适的地方正确地投入。

有没有办法(或相关功能)以某种方式报告是否实际提交?如果有的话,我可以设置一些监视以跟踪这些事件并随着时间的流逝而慢慢解决。

I'm using the MySQL Python Connector

At the beginning of all requests, I take a database connection from the connection pool. At the end of all requests, I commit the connection to ensure that no uncommitted transactions are inadvertently lost. However, I would like to find these uncommitted transactions in an automated way, so that they can be properly committed in their more appropriate place.

Is there a way for Connection.commit() (or a related function) to somehow report if anything was actually committed? If there was, I can set up some monitoring to track these events and slowly resolve them over time.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏至、离别 2025-01-29 02:14:13

计划A:始终使用自动企业打开。对于某些类型的应用程序来说,这足够了,但不利用“交易”。例如,对于“银行”申请而言,这不是明智的。对于不存在多个连接资源的连接的随意应用程序,可能是可以的。或如果服务器在运行中间崩溃,那不会受到严重伤害的应用程序。

计划B:要始终明确使用开始和承诺。

计划C:混合A和B。离开自动启动,但有时会使用启动和提交。这为您提供了B(需要时)的安全性,以及A的简单性(其余时间)。

计划D:不要使用此!关闭AutoCommit,并希望记住最终指定 commit 。您似乎就是这样。

(PS:这适用于所有应用程序,而不仅仅是Python。)

Plan A: Always run with autocommit turned on. This is sufficient for some types of applications, but does not make use of "transactions". This is not wise, for example, for a "bank" application. It is probably OK for casual applications where there won't be multiple connections competing for resources. Or apps that won't be seriously hurt if the server crashes in the middle of a run.

Plan B: Be religious about always explicitly using Start and Commit.

Plan C: Mix A and B. Leave autocommit ON, but sometimes use Start and Commit. This gives you the security of B (when needed), together with the simplicity of A (the rest of the time).

Plan D: DO NOT USE THIS! Turn autocommit OFF and hope to remember to specify COMMIT eventually. This seems to be the case you are in.

(PS: This applies for all apps, not just Python.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文