由于某些奇怪的原因,我无法从Python测试应用程序中获取callproc调用的结果.MqSQL 5.2.47中的存储过程如下所示:
CREATE PROCEDURE `mytestdb`.`getperson` (IN personid INT)
BEGIN
select person.person_id,
person.person_fname,
person.person_mi,
person.person_lname,
person.persongender_id,
person.personjob_id
from person
where person.person_id = personid;
END
Run Code Online (Sandbox Code Playgroud)
现在,使用PyCharm和Python 3.3,我似乎无法在调用此存储过程时检索任何内容.这段代码得到了我想要的结果:
import mysql.connector
cnx = mysql.connector.connect(user='root', host='127.0.0.1', database='mytestdb')
cnx._open_connection()
cursor = cnx.cursor()
cursor.execute("select * from person where person.person_id = 1")
people = cursor.fetchall()
for person in people:
print(person)
cnx.close()
Run Code Online (Sandbox Code Playgroud)
但是这个代码有cursor.fetchall()或cursor.fetchone()......
import mysql.connector
cnx = mysql.connector.connect(user='root', host='127.0.0.1', database='mytestdb')
cnx._open_connection()
cursor = cnx.cursor()
cursor.callproc("getperson", [1])
people = cursor.fetchall()
for person in people:
print(person)
cnx.close()
Run Code Online (Sandbox Code Playgroud)
...返回"mysql.connector.errors.InterfaceError:没有结果集来取自." 使用cursor.execute()方法还有一个奇怪的行为,就像这样......
import mysql.connector …Run Code Online (Sandbox Code Playgroud)