Skip to content

Commit c9e349d

Browse files
authored
Align % formatting in Cursor.executemany() with Cursor.execute() (#721)
ports the changes from PyMySQL/PyMySQL#450 also, fix the test case for detecting whether executemany() just called execute() multiple times
1 parent 2aef3c7 commit c9e349d

File tree

3 files changed

+4
-10
lines changed

3 files changed

+4
-10
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ To be included in 1.0.0 (unreleased)
1616
* Remove deprecated no_delay argument #702
1717
* Support PyMySQL up to version 1.0.2 #643
1818
* Bump minimal PyMySQL version to 1.0.0 #713
19+
* Align % formatting in Cursor.executemany() with Cursor.execute(), literal % now need to be doubled in Cursor.executemany() #714
1920

2021

2122
0.0.22 (2021-11-14)

aiomysql/cursors.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# https://github.com/PyMySQL/PyMySQL/blob/master/pymysql/cursors.py#L11-L18
1515

1616
#: Regular expression for :meth:`Cursor.executemany`.
17-
#: executemany only suports simple bulk insert.
17+
#: executemany only supports simple bulk insert.
1818
#: You can use it to load large dataset.
1919
RE_INSERT_VALUES = re.compile(
2020
r"\s*((?:INSERT|REPLACE)\s.+\sVALUES?\s+)" +
@@ -274,7 +274,7 @@ async def executemany(self, query, args):
274274

275275
m = RE_INSERT_VALUES.match(query)
276276
if m:
277-
q_prefix = m.group(1)
277+
q_prefix = m.group(1) % ()
278278
q_values = m.group(2).rstrip()
279279
q_postfix = m.group(3) or ''
280280
assert q_values[0] == '(' and q_values[-1] == ')'

tests/test_cursor.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import pytest
44

5-
from pymysql.err import OperationalError
6-
75
from aiomysql import ProgrammingError, Cursor, InterfaceError
86
from aiomysql.cursors import RE_INSERT_VALUES
97

@@ -339,11 +337,6 @@ async def test_execute_percentage(connection_creator):
339337
await cur.execute(q, (3, 4))
340338

341339

342-
@pytest.mark.xfail(
343-
reason="https://github.com/aio-libs/aiomysql/pull/545",
344-
raises=OperationalError,
345-
strict=True,
346-
)
347340
@pytest.mark.run_loop
348341
async def test_executemany_percentage(connection_creator):
349342
# %% in column set
@@ -359,5 +352,5 @@ async def test_executemany_percentage(connection_creator):
359352

360353
assert RE_INSERT_VALUES.match(q) is not None
361354
await cur.executemany(q, [(3, 4), (5, 6)])
362-
assert cur._last_executed.endswith("(3, 4),(5, 6)"), \
355+
assert cur._last_executed.endswith(b"(3, 4),(5, 6)"), \
363356
"executemany with %% not in one query"

0 commit comments

Comments
 (0)