Skip to content

Commit 354dcb5

Browse files
authored
Allow bulk insert which no space around VALUES (#179)
1 parent 1693848 commit 354dcb5

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

MySQLdb/cursors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#: executemany only supports simple bulk insert.
2727
#: You can use it to load large dataset.
2828
RE_INSERT_VALUES = re.compile(
29-
r"\s*((?:INSERT|REPLACE)\s.+\sVALUES?\s+)" +
29+
r"\s*((?:INSERT|REPLACE)\b.+\bVALUES?\s*)" +
3030
r"(\(\s*(?:%s|%\(.+\)s)\s*(?:,\s*(?:%s|%\(.+\)s)\s*)*\))" +
3131
r"(\s*(?:ON DUPLICATE.*)?);?\s*\Z",
3232
re.IGNORECASE | re.DOTALL)

tests/test_cursor.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ def test_executemany():
4949
assert m is not None, 'error parse %(id_name)s'
5050
assert m.group(3) == ' ON duplicate update', 'group 3 not ON duplicate update, bug in RE_INSERT_VALUES?'
5151

52+
# https://github.com/PyMySQL/mysqlclient-python/issues/178
53+
m = MySQLdb.cursors.RE_INSERT_VALUES.match("INSERT INTO bloup(foo, bar)VALUES(%s, %s)")
54+
assert m is not None
55+
5256
# cursor._executed myst bee "insert into test (data) values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9)"
5357
# list args
5458
data = range(10)

0 commit comments

Comments
 (0)