如何判断您的select查询是否在一个事务中? [英] How to tell if your select query is within a transaction or not?

查看:649
本文介绍了如何判断您的select查询是否在一个事务中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Django 1.5.x中,我有一个长时间运行的管理命令,其中select查询返回陈旧的数据。我怀疑这是因为它们在早期在db连接上启动的事务中运行。有没有办法告诉一个查询是在一个事务中运行还是处于自动提交模式?

In Django 1.5.x, I have a long running management command where select queries are returning stale data. I suspect this is due to the fact that they are running within a transaction that are started earlier on the db connnection. Is there a way a tell if a query runs within a transaction or it is in autocommit mode?

(这是一个较为重点的版本, a href =https://stackoverflow.com/questions/18540099/orm-does-not-return-recent-database-changes> https://stackoverflow.com/questions/18540099/orm-does-not-return -recent-database-changes )

(this is somewhat more focused version of an earlier question I posted at https://stackoverflow.com/questions/18540099/orm-does-not-return-recent-database-changes)

推荐答案

您可以通过检查 is_managed

if transaction.is_managed():
    print "tutsi frutsi!"

这篇关于如何判断您的select查询是否在一个事务中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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