8000 Cursor.fetchall() always return list. by methane · Pull Request #1115 · PyMySQL/PyMySQL · GitHub
[go: up one dir, main page]

Skip to content

Cursor.fetchall() always return list. #1115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion pymysql/cursors.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ def fetchmany(self, size=None):
"""Fetch several rows."""
self._check_executed()
if self._rows is None:
# Django expects () for EOF.
# https://github.com/django/django/blob/0c1518ee429b01c145cf5b34eab01b0b92f8c246/django/db/backends/mysql/features.py#L8
return ()
end = self.rownumber + (size or self.arraysize)
result = self._rows[self.rownumber : end]
Expand All @@ -292,7 +294,7 @@ def fetchall(self):
"""Fetch all the rows."""
self._check_executed()
if self._rows is None:
return ()
return []
if self.rownumber:
result = self._rows[self.rownumber :]
else:
Expand Down Expand Up @@ -479,6 +481,10 @@ def fetchmany(self, size=None):
break
rows.append(row)
self.rownumber += 1
if not rows:
# Django expects () for EOF.
# https://github.com/django/django/blob/0c1518ee429b01c145cf5b34eab01b0b92f8c246/django/db/backends/mysql/features.py#L8
return ()
return rows

def scroll(self, value, mode="relative"):
Expand Down
2 changes: 1 addition & 1 deletion pymysql/tests/test_nextset.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_nextset_error(self):
self.assertEqual([(i,)], list(cur))
with self.assertRaises(pymysql.ProgrammingError):
cur.nextset()
self.assertEqual((), cur.fetchall())
self.assertEqual([], cur.fetchall())

def test_ok_and_next(self):
cur = self.connect(client_flag=CLIENT.MULTI_STATEMENTS).cursor()
Expand Down
0