Bug #71450 retrieve statement(cursor) on error from cursor.execute(query, multi=True)
Submitted: 21 Jan 2014 21:47
Reporter: Kevin Heaps Email Updates:
Status: Open Impact on me:
Category:Connector / Python Severity:S4 (Feature request)
Version:1.1.4 OS:Any
Assigned to: CPU Architecture:Any

[21 Jan 2014 21:47] Kevin Heaps
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()
    for result in mycursor.execute(query, multi=True):
        if result.with_rows:
            for row in result:
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.