]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
refactor: merge BaseCursor's _set_results() and _set_results_from_pipeline()
authorDenis Laxalde <denis@laxalde.org>
Mon, 9 Jan 2023 20:26:46 +0000 (21:26 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sat, 4 Feb 2023 11:16:29 +0000 (12:16 +0100)
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
psycopg/psycopg/cursor.py

index 233d66b234f4664182e2282d00e4a32214196de3..5205765b3ab18e743ba4c1339e0e1318358f1239 100644 (file)
@@ -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.
index 75c4ada9332c70298a7f1722cfe2a6d423cceb9c..d65be6ae8025c64752ba84c6e5eea2921716bea7 100644 (file)
@@ -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: