diff --git a/pymysql/cursors.py b/pymysql/cursors.py index f17611b..1792eaf 100644 --- a/pymysql/cursors.py +++ b/pymysql/cursors.py @@ -13,7 +13,7 @@ from . import err #: executemany only suports simple bulk insert. #: You can use it to load large dataset. RE_INSERT_VALUES = re.compile( - r"\s*(INSERT\s.+\sVALUES\s+)" + + r"\s*((?:INSERT|REPLACE)\s.+\sVALUES?\s+)" + r"(\(\s*(?:%s|%\(.+\)s)\s*(?:,\s*(?:%s|%\(.+\)s)\s*)*\))" + r"(\s*(?:ON DUPLICATE.*)?)\Z", re.IGNORECASE | re.DOTALL) @@ -163,10 +163,16 @@ class Cursor(object): return result def executemany(self, query, args): + # type: (str, list) -> int """Run several data against one query - PyMySQL can execute bulkinsert for query like 'INSERT ... VALUES (%s)'. - In other form of queries, just run :meth:`execute` many times. + :param query: query to execute on server + :param args: Sequence of sequences or mappings. It is used as parameter. + :return: Number of rows affected, if any. + + This method improves performance on multiple-row INSERT and + REPLACE. Otherwise it is equivalent to looping over args with + execute(). """ if not args: return