Skip to content

Commit ed5efda

Browse files
uwydocmethane
authored andcommitted
allow no whitespaces between VALUES and ( when do bulk insert/replace (PyMySQL#597)
1 parent dc01c6e commit ed5efda

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

pymysql/cursors.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#: executemany only suports simple bulk insert.
1313
#: You can use it to load large dataset.
1414
RE_INSERT_VALUES = re.compile(
15-
r"\s*((?:INSERT|REPLACE)\s.+\sVALUES?\s+)" +
15+
r"\s*((?:INSERT|REPLACE)\b.+\bVALUES?\s*)" +
1616
r"(\(\s*(?:%s|%\(.+\)s)\s*(?:,\s*(?:%s|%\(.+\)s)\s*)*\))" +
1717
r"(\s*(?:ON DUPLICATE.*)?);?\s*\Z",
1818
re.IGNORECASE | re.DOTALL)

pymysql/tests/test_cursor.py

+4
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ def test_executemany(self):
7979
self.assertIsNotNone(m, 'error parse %(id_name)s')
8080
self.assertEqual(m.group(3), ' ON duplicate update', 'group 3 not ON duplicate update, bug in RE_INSERT_VALUES?')
8181

82+
# https://github.com/PyMySQL/PyMySQL/pull/597
83+
m = pymysql.cursors.RE_INSERT_VALUES.match("INSERT INTO bloup(foo, bar)VALUES(%s, %s)")
84+
assert m is not None
85+
8286
# cursor._executed must bee "insert into test (data) values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9)"
8387
# list args
8488
data = range(10)

0 commit comments

Comments
 (0)