Support REPLACE statement in executemany

This commit is contained in:
INADA Naoki
2016-05-13 02:19:33 +09:00
parent 784c5e511b
commit 757c3bc498

View File

@@ -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