Support REPLACE statement in executemany
This commit is contained in:
@@ -13,7 +13,7 @@ from . import err
|
|||||||
#: executemany only suports simple bulk insert.
|
#: executemany only suports simple bulk insert.
|
||||||
#: You can use it to load large dataset.
|
#: You can use it to load large dataset.
|
||||||
RE_INSERT_VALUES = re.compile(
|
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*(?:%s|%\(.+\)s)\s*(?:,\s*(?:%s|%\(.+\)s)\s*)*\))" +
|
||||||
r"(\s*(?:ON DUPLICATE.*)?)\Z",
|
r"(\s*(?:ON DUPLICATE.*)?)\Z",
|
||||||
re.IGNORECASE | re.DOTALL)
|
re.IGNORECASE | re.DOTALL)
|
||||||
@@ -163,10 +163,16 @@ class Cursor(object):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
def executemany(self, query, args):
|
def executemany(self, query, args):
|
||||||
|
# type: (str, list) -> int
|
||||||
"""Run several data against one query
|
"""Run several data against one query
|
||||||
|
|
||||||
PyMySQL can execute bulkinsert for query like 'INSERT ... VALUES (%s)'.
|
:param query: query to execute on server
|
||||||
In other form of queries, just run :meth:`execute` many times.
|
: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:
|
if not args:
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user