Description:
When using cursor.execute with multi=True, it proves difficult if not impossible to show the statement that caused an error to be raised, since the result is handled before the statement is stored to self._executed
How to repeat:
Ideally, the following construct is possible:
query = "SELECT 1; SELECT 2; SELECT x"
mycursor = cnx.cursor()
try:
for result in mycursor.execute(query, multi=True):
if result.with_rows:
print(result.column_names)
for row in result:
print(row)
else:
print(result.rowcount)
except mysql.connector.errors.ProgrammingError as e:
print("Error Code:{}in\n{}".format(e, cursor.statement), file=sys.stderr)
Suggested fix:
This may be as simple as swapping two lines in the code (ex., in v1.1.4 for python3 mysql.connector.cursor.py, lines 452 and 453). More properly, perhaps it would be an attribute of the error that was raised.