From 0123f15ccd44fc7b0101167f28a0b3a7aba96398 Mon Sep 17 00:00:00 2001 From: Denis Laxalde Date: Mon, 9 Jan 2023 21:26:46 +0100 Subject: [PATCH] refactor: merge BaseCursor's _set_results() and _set_results_from_pipeline() Per refactoring of previous commits, these are similar: the only difference is the use of "first_batch" flag in the execute() branch when not in pipeline mode, but in that case since there is actually only one "batch", the behavior is actually preserved. Since _set_results_from_pipeline() previously included a call to _check_results() but _set_results() does not, that is reported in caller (BasePipeline._process_results()). --- psycopg/psycopg/_pipeline.py | 3 ++- psycopg/psycopg/cursor.py | 20 -------------------- 2 files changed, 2 insertions(+), 21 deletions(-) diff --git a/psycopg/psycopg/_pipeline.py b/psycopg/psycopg/_pipeline.py index 233d66b23..5205765b3 100644 --- a/psycopg/psycopg/_pipeline.py +++ b/psycopg/psycopg/_pipeline.py @@ -190,7 +190,8 @@ class BasePipeline: raise e.PipelineAborted("pipeline aborted") else: cursor, prepinfo = queued - cursor._set_results_from_pipeline(results) + cursor._check_results(results) + cursor._set_results(results) if prepinfo: key, prep, name = prepinfo # Update the prepare state of the query. diff --git a/psycopg/psycopg/cursor.py b/psycopg/psycopg/cursor.py index 75c4ada93..d65be6ae8 100644 --- a/psycopg/psycopg/cursor.py +++ b/psycopg/psycopg/cursor.py @@ -523,26 +523,6 @@ class BaseCursor(Generic[ConnectionType, Row]): self._make_row = self._make_row_maker() def _set_results(self, results: List["PGresult"]) -> None: - if self._execmany_returning is None: - # Received from execute() - self._results = results - self._select_current_result(0) - - else: - # Received from executemany() - if self._execmany_returning: - first_batch = not self._results - self._results.extend(results) - if first_batch: - self._select_current_result(0) - else: - # In non-returning case, set rowcount to the cumulated number - # of rows of executed queries. - for res in results: - self._rowcount += res.command_tuples or 0 - - def _set_results_from_pipeline(self, results: List["PGresult"]) -> None: - self._check_results(results) first_batch = not self._results if self._execmany_returning is None: -- 2.47.2