pymysql调用存储过程获取多个结果集,并以多个json组成数组的形式返回
效果图:
代码:
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QTableWidgetItem, QTableWidget
import pymysql
from pymysql import cursors
connection = pymysql.connect(
host='127.0.0.1',
port=3306,
user='root',
password='123456',
db='database_name',
charset='utf8',
cursorclass=cursors.DictCursor
)
try:
with connection.cursor() as cursor:
results = []
# 调用存储过程
cursor.execute('call test_proc(1)')
# 获取第一个结果集
result = cursor.fetchall()
results.append(result)
# 获取第二个结果集
for i in range(1, 100) :
if cursor.nextset():
result = cursor.fetchall()
results.append(result)
else:
break
print(results[i - 1])
#return result, result2
finally:
connection.close()