如何使用 MySQLdb 从 Python 更改 SQL 隔离级别?
我研究过的文档表明,对其他数据库执行此操作的方法是在查询中使用多个语句,a la:
>>> cursor = connection.cursor()
>>> cursor.execute("set session transaction isolation level read uncommitted;
select stuff from table;
set session transaction isolation level repeatable read;")
不幸的是,这样做不会产生任何结果,显然是 Python DB API(或者可能只是这个)它的实现?)不支持单个查询中的多个记录集。
过去有其他人在这方面取得过成功吗?
The documentation I've run across researching this indicates that the way to do it for other databases is to use multiple statements in your query, a la:
>>> cursor = connection.cursor()
>>> cursor.execute("set session transaction isolation level read uncommitted;
select stuff from table;
set session transaction isolation level repeatable read;")
Unfortunately, doing that yields no results, as apparently the Python DB API (or maybe just this implementation of it?) doesn't support multiple recordsets within a single query.
Has anyone else had success with this in the past?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为这不适用于 MySQLdb 驱动程序;你必须发出单独的查询:
MySQLdb游标的execute()方法只能看到第一个查询到分号:
I don't think this works for the MySQLdb driver; you'll have to issue separate queries:
The MySQLdb cursor's execute() method only sees the first query up to the semicolon:
使用
cur.executemany
运行多个 sql 语句;分开了。use
cur.executemany
to run multiple sql statements with ; separated.