MySQL连接器方法`fetchone`和`fetchmany`不符合PEP 249

时间:2017-09-19 13:36:30

标签: python mysql mysql-connector pep

在Windows 10上使用Python 3.6.2MySQL Connector 2.1.6包,不调用数据库游标的execute方法,或在 {{1}上调用它语句(SELECTCREATEDROPALTERINSERTDELETE等)会产生以下结果:

UPDATE

PEP 249明确说明了>>> import mysql.connector >>> session = mysql.connector.connect(user = "root", database = "mysql") >>> cursor = session.cursor() >>> cursor.fetchone() >>> cursor.fetchmany() [] >>> cursor.fetchall() Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Users\Maggyero\AppData\Local\Programs\Python\Python36-32\lib\site-packages\mysql\connector\cursor.py", line 891, in fetchall raise errors.InterfaceError("No result set to fetch from.") mysql.connector.errors.InterfaceError: No result set to fetch from. >>> cursor.execute("CREATE TABLE test (x INTEGER)") >>> cursor.fetchone() >>> cursor.fetchmany() [] >>> cursor.fetchall() Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Users\Maggyero\AppData\Local\Programs\Python\Python36-32\lib\site-packages\mysql\connector\cursor.py", line 891, in fetchall raise errors.InterfaceError("No result set to fetch from.") mysql.connector.errors.InterfaceError: No result set to fetch from. fetchonefetchmany方法:

  

如果先前对.execute *()的调用未产生任何结果集或尚未发出任何调用,则会引发错误(或子类)异常。

那么为什么不fetchallfetchone引发fetchmany之类的异常?

1 个答案:

答案 0 :(得分:0)

我在 bugs.mysql.com 上提交了 bug report,该错误已在 MySQL Connector/Python 8.0.23 中修复。