Skip to content

Commit

Permalink
Import PyMySQL bugfix #649 (#313)
Browse files Browse the repository at this point in the history
* Pulled test from PyMySQL cf1c74c213eebeaad706a7bc53d729c9ddbb54fd

* Imported PyMySQL changes to fix nextset bug
  • Loading branch information
terrycain authored and jettify committed Jul 9, 2018
1 parent 6e40bac commit 425f81e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions aiomysql/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,7 @@ def _write_bytes(self, data):
return self._writer.write(data)

async def _read_query_result(self, unbuffered=False):
self._result = None
if unbuffered:
try:
result = MySQLResult(self)
Expand Down
12 changes: 12 additions & 0 deletions aiomysql/cursors.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ async def nextset(self):
return
if not current_result.has_next:
return
self._result = None
self._clear_result()
await conn.next_result()
await self._do_get_result()
return True
Expand Down Expand Up @@ -449,9 +451,19 @@ def scroll(self, value, mode='relative'):
async def _query(self, q):
conn = self._get_db()
self._last_executed = q
self._clear_result()
await conn.query(q)
await self._do_get_result()

def _clear_result(self):
self._rownumber = 0
self._result = None

self._rowcount = 0
self._description = None
self._lastrowid = None
self._rows = None

async def _do_get_result(self):
conn = self._get_db()
self._rownumber = 0
Expand Down
12 changes: 12 additions & 0 deletions tests/test_nextset.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import asyncio

import pytest
from pymysql.err import ProgrammingError


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


@pytest.mark.run_loop
async def test_nextset_error(cursor):
await cursor.execute("SELECT 1; xyzzy;")

# nextset shouldn't hang on error, it should raise syntax error
with pytest.raises(ProgrammingError):
await asyncio.wait_for(cursor.nextset(), 5)


@pytest.mark.run_loop
async def test_ok_and_next(cursor):
await cursor.execute("SELECT 1; commit; SELECT 2;")
Expand Down

0 comments on commit 425f81e

Please sign in to comment.