From: Denis Laxalde Date: Sat, 2 Oct 2021 13:47:43 +0000 (+0200) Subject: Possibly use C impl of send() and fetch() in Cursor.stream() X-Git-Tag: 3.0~28^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5266c43491f2544f7bcb4eeb9660a55e14be352f;p=thirdparty%2Fpsycopg.git Possibly use C impl of send() and fetch() in Cursor.stream() Taking advantage of these functions being available per previous commit. --- diff --git a/psycopg/psycopg/cursor.py b/psycopg/psycopg/cursor.py index 58deeaba3..86272d8fa 100644 --- a/psycopg/psycopg/cursor.py +++ b/psycopg/psycopg/cursor.py @@ -13,7 +13,6 @@ from contextlib import contextmanager from . import pq from . import adapt from . import errors as e -from . import generators from .pq import ExecStatus, Format from .abc import ConnectionType, Query, Params, PQGen @@ -34,9 +33,15 @@ execute: Callable[["PGconn"], PQGen[List["PGresult"]]] if _psycopg: execute = _psycopg.execute + fetch = _psycopg.fetch + send = _psycopg.send else: + from . import generators + execute = generators.execute + fetch = generators.fetch + send = generators.send class BaseCursor(Generic[ConnectionType, Row]): @@ -270,8 +275,8 @@ class BaseCursor(Generic[ConnectionType, Row]): self._last_query = query def _stream_fetchone_gen(self, first: bool) -> PQGen[Optional["PGresult"]]: - yield from generators.send(self._pgconn) - res = yield from generators.fetch(self._pgconn) + yield from send(self._pgconn) + res = yield from fetch(self._pgconn) if res is None: return None @@ -286,7 +291,7 @@ class BaseCursor(Generic[ConnectionType, Row]): # End of single row results status = res.status while res: - res = yield from generators.fetch(self._pgconn) + res = yield from fetch(self._pgconn) if status != ExecStatus.TUPLES_OK: raise e.ProgrammingError( "the operation in stream() didn't produce a result"