MySQL 连接器方法“fetchone”和“fetchmany”不符合 PEP 249
MySQL Connector methods `fetchone` and `fetchmany` are not PEP 249 compliant
With Python 3.6.2 and MySQL Connector 2.1.6 package on Windows 10,不调用数据库游标的 execute
方法,或在 non 上调用它SELECT
语句(CREATE
、DROP
、ALTER
、INSERT
、DELETE
、UPDATE
等)产生以下结果:
>>> 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.
PEP 249 明确说明 fetchone
、fetchmany
和 fetchall
方法:
An Error (or subclass) exception is raised if the previous call to .execute*() did not produce any result set or no call was issued yet.
那么为什么 fetchone
和 fetchmany
不引发像 fetchall
这样的异常?
我在 bugs.mysql.com 上提交了 bug report,该错误已在 MySQL Connector/Python 8.0.23.
中修复
With Python 3.6.2 and MySQL Connector 2.1.6 package on Windows 10,不调用数据库游标的 execute
方法,或在 non 上调用它SELECT
语句(CREATE
、DROP
、ALTER
、INSERT
、DELETE
、UPDATE
等)产生以下结果:
>>> 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.
PEP 249 明确说明 fetchone
、fetchmany
和 fetchall
方法:
An Error (or subclass) exception is raised if the previous call to .execute*() did not produce any result set or no call was issued yet.
那么为什么 fetchone
和 fetchmany
不引发像 fetchall
这样的异常?
我在 bugs.mysql.com 上提交了 bug report,该错误已在 MySQL Connector/Python 8.0.23.
中修复