Bug #109024 MySQL Connector/Python Invalid executemany function
Submitted: 8 Nov 2022 7:49 Modified: 9 Nov 2022 14:50
Reporter: jie li Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / Python Severity:S2 (Serious)
Version:8.0 OS:Any
Assigned to: CPU Architecture:Any

[8 Nov 2022 7:49] jie li
Description:
The coding in the source code results in an inability to get the desired flow
The RE results in a failure to match the correct sql

An extra pair of curly braces Lead to Invalid executemany function

{{0,2}

RE_SQL_INSERT_STMT = re.compile(
    rf"({SQL_COMMENT}|\s)*INSERT({SQL_COMMENT}|\s)"
    r"*INTO\s+[`'\"]?.+[`'\"]?(?:\.[`'\"]?.+[`'\"]?)"
    r"{{0,2}}\s+VALUES\s*\(.+(?:\s*,.+)*\)",
    re.I | re.M | re.S,
)

How to repeat:
import re
SQL_COMMENT = r"\/\*.*?\*\/"
RE_SQL_INSERT_STMT = re.compile(
   rf"({SQL_COMMENT}|\s)*INSERT({SQL_COMMENT}|\s)"
    r"*INTO\s+[`'\"]?.+[`'\"]?(?:\.[`'\"]?.+[`'\"]?)"
    r"{{0,2}}\s+VALUES\s*\(.+(?:\s*,.+)*\)",
    re.I | re.M | re.S,
  )

if re.match(RE_SQL_INSERT_STMT, "INSERT INTO employees(first_name, hire_date) VALUES  ('%s', '%s')"):
    print(1)

Suggested fix:
RE_SQL_INSERT_STMT = re.compile(
    rf"({SQL_COMMENT}|\s)*INSERT({SQL_COMMENT}|\s)"
    r"*INTO\s+[`'\"]?.+[`'\"]?(?:\.[`'\"]?.+[`'\"]?)"
    r"{0,2}\s+VALUES\s*\(.+(?:\s*,.+)*\)",
    re.I | re.M | re.S,
)
[9 Nov 2022 10:59] MySQL Verification Team
Hello jie li,

Thank you for the report and feedback.

regards,
Umesh
[9 Nov 2022 14:41] Nuno Mariz
Posted by developer:
 
This bug was fixed by BUG#34499578.
Thank you for your contribution.