From: Daniele Varrazzo Date: Fri, 12 Feb 2021 01:36:01 +0000 (+0100) Subject: Merge branch 'master' into row-factory X-Git-Tag: 3.0.dev0~106^2~18 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=606d33a08e88ee6e344fbf33a9c2a4362c624186;p=thirdparty%2Fpsycopg.git Merge branch 'master' into row-factory --- 606d33a08e88ee6e344fbf33a9c2a4362c624186 diff --cc psycopg3/psycopg3/cursor.py index c24a3f985,807ee1f42..db87c83d2 --- a/psycopg3/psycopg3/cursor.py +++ b/psycopg3/psycopg3/cursor.py @@@ -277,11 -270,8 +276,10 @@@ class BaseCursor(Generic[ConnectionType return None elif res.status == ExecStatus.SINGLE_TUPLE: - if self._row_factory: + self.pgresult = res + self._tx.set_pgresult(res, set_loaders=first) ++ if first and self._row_factory: + self._tx.make_row = self._row_factory(self) - self.pgresult = res # will set it on the transformer too - # TODO: the transformer may do excessive work here: create a - # path that doesn't clear the loaders every time. return res elif res.status in (ExecStatus.TUPLES_OK, ExecStatus.COMMAND_OK): @@@ -382,8 -373,7 +381,9 @@@ self._results = list(results) self.pgresult = results[0] + self._tx.set_pgresult(results[0]) + if self._row_factory: + self._tx.make_row = self._row_factory(self) nrows = self.pgresult.command_tuples if nrows is not None: if self._rowcount < 0: @@@ -527,8 -518,9 +528,9 @@@ class Cursor(BaseCursor["Connection"]) rec = self._tx.load_row(0) assert rec is not None yield rec + first = False - def fetchone(self) -> Optional[Sequence[Any]]: + def fetchone(self) -> Optional[Row]: """ Return the next record from the current recordset. @@@ -643,15 -635,17 +645,17 @@@ class AsyncCursor(BaseCursor["AsyncConn async def stream( self, query: Query, params: Optional[Params] = None - ) -> AsyncIterator[Sequence[Any]]: + ) -> AsyncIterator[Row]: async with self._conn.lock: await self._conn.wait(self._stream_send_gen(query, params)) - while await self._conn.wait(self._stream_fetchone_gen()): + first = True + while await self._conn.wait(self._stream_fetchone_gen(first)): rec = self._tx.load_row(0) assert rec is not None yield rec + first = False - async def fetchone(self) -> Optional[Sequence[Any]]: + async def fetchone(self) -> Optional[Row]: self._check_result() rv = self._tx.load_row(self._pos) if rv is not None: diff --cc psycopg3_c/psycopg3_c/_psycopg3.pyi index fc603dd3e,5b9adf88a..756c34e63 --- a/psycopg3_c/psycopg3_c/_psycopg3.pyi +++ b/psycopg3_c/psycopg3_c/_psycopg3.pyi @@@ -22,13 -22,10 +22,14 @@@ class Transformer(proto.AdaptContext) @property def adapters(self) -> AdaptersMap: ... @property + def make_row(self) -> Optional[proto.RowMaker]: ... + @make_row.setter + def make_row(self, row_maker: proto.RowMaker) -> None: ... + @property def pgresult(self) -> Optional[PGresult]: ... - @pgresult.setter - def pgresult(self, result: Optional[PGresult]) -> None: ... + def set_pgresult( + self, result: Optional["PGresult"], set_loaders: bool = True + ) -> None: ... def set_row_types( self, types: Sequence[int], formats: Sequence[pq.Format] ) -> None: ...