]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
refactor: introduce BaseCursor._set_results()
authorDenis Laxalde <denis@laxalde.org>
Sat, 7 Jan 2023 07:31:41 +0000 (08:31 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sat, 4 Feb 2023 11:16:29 +0000 (12:16 +0100)
Similar to _set_results_from_pipeline(), this applies to the
non-pipeline case and reduce code repetition.

psycopg/psycopg/cursor.py

index 8379c589ab2835a6d08542dfaf736e474652601e..30dcb977484a017eeaebcbc74c1c0ba4ca2e4dcd 100644 (file)
@@ -201,8 +201,7 @@ class BaseCursor(Generic[ConnectionType, Row]):
         else:
             assert results is not None
             self._check_results(results)
-            self._results = results
-            self._select_current_result(0)
+            self._set_results(results)
 
         self._last_query = query
 
@@ -413,8 +412,7 @@ class BaseCursor(Generic[ConnectionType, Row]):
             raise e.ProgrammingError("COPY cannot be mixed with other operations")
 
         self._check_copy_result(results[0])
-        self._results = results
-        self._select_current_result(0)
+        self._set_results(results)
 
     def _execute_send(
         self,
@@ -529,6 +527,10 @@ class BaseCursor(Generic[ConnectionType, Row]):
 
         self._make_row = self._make_row_maker()
 
+    def _set_results(self, results: List["PGresult"]) -> None:
+        self._results = results
+        self._select_current_result(0)
+
     def _set_results_from_pipeline(self, results: List["PGresult"]) -> None:
         self._check_results(results)
         first_batch = not self._results