MySQL Connector/Python Release Notes
Syntax:
for statement, result_set in cursor.fetchsets():
# do something with statement and/or result set
This method generates a set of result sets caused by the last cursor.execute*(). It returns a generator where each item is a 2-tuple; the first element is the statement that caused the result set, and the second is the result set itself.
This method can be used as part of the multi statement execution workflow.
sql_operation = '''
SET @a=1, @b='2025-01-01';
SELECT @a, LENGTH('hello'), @b;
SELECT @@version;
'''
with cnx.cursor() as cur:
cur.execute(sql_operation)
for statement, result_set in cur.fetchsets():
# do something with statement and/or result set
This method was added in Connector/Python 9.2.0.