Skip to content

Commit 425f81e

Browse files
terrycainjettify
authored andcommitted
Import PyMySQL bugfix #649 (#313)
* Pulled test from PyMySQL cf1c74c213eebeaad706a7bc53d729c9ddbb54fd * Imported PyMySQL changes to fix nextset bug
1 parent 6e40bac commit 425f81e

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

aiomysql/connection.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,7 @@ def _write_bytes(self, data):
589589
return self._writer.write(data)
590590

591591
async def _read_query_result(self, unbuffered=False):
592+
self._result = None
592593
if unbuffered:
593594
try:
594595
result = MySQLResult(self)

aiomysql/cursors.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ async def nextset(self):
184184
return
185185
if not current_result.has_next:
186186
return
187+
self._result = None
188+
self._clear_result()
187189
await conn.next_result()
188190
await self._do_get_result()
189191
return True
@@ -449,9 +451,19 @@ def scroll(self, value, mode='relative'):
449451
async def _query(self, q):
450452
conn = self._get_db()
451453
self._last_executed = q
454+
self._clear_result()
452455
await conn.query(q)
453456
await self._do_get_result()
454457

458+
def _clear_result(self):
459+
self._rownumber = 0
460+
self._result = None
461+
462+
self._rowcount = 0
463+
self._description = None
464+
self._lastrowid = None
465+
self._rows = None
466+
455467
async def _do_get_result(self):
456468
conn = self._get_db()
457469
self._rownumber = 0

tests/test_nextset.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
import asyncio
2+
13
import pytest
4+
from pymysql.err import ProgrammingError
25

36

47
@pytest.mark.run_loop
@@ -27,6 +30,15 @@ async def test_skip_nextset(cursor):
2730
assert [(42,)] == list(r)
2831

2932

33+
@pytest.mark.run_loop
34+
async def test_nextset_error(cursor):
35+
await cursor.execute("SELECT 1; xyzzy;")
36+
37+
# nextset shouldn't hang on error, it should raise syntax error
38+
with pytest.raises(ProgrammingError):
39+
await asyncio.wait_for(cursor.nextset(), 5)
40+
41+
3042
@pytest.mark.run_loop
3143
async def test_ok_and_next(cursor):
3244
await cursor.execute("SELECT 1; commit; SELECT 2;")

0 commit comments

Comments
 (0)