对于Windows 10上的Python 3.6.2和MySQL Connector 2.1.6包,不调用数据库游标的execute
方法,或在非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
和{
目前没有回答
相关问题 更多 >
编程相关推荐