]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Drop Cursor._set_results()
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sun, 2 Jan 2022 18:22:34 +0000 (19:22 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sun, 2 Jan 2022 19:55:58 +0000 (20:55 +0100)
Split it into a _check_results() and leave the caller manage the cursor state.

psycopg/psycopg/cursor.py
psycopg/psycopg/server_cursor.py

index 8527cf9d32d003f26b35f9d632133d62b3299a16..1f369d7302f69f47dd6e244dc8e13e60207297fe 100644 (file)
@@ -197,7 +197,8 @@ class BaseCursor(Generic[ConnectionType, Row]):
         results = yield from self._maybe_prepare_gen(
             pgq, prepare=prepare, binary=binary
         )
-        self._set_results(results)
+        self._check_results(results)
+        self._results = results
         self._set_result(0)
         self._last_query = query
 
@@ -220,7 +221,7 @@ class BaseCursor(Generic[ConnectionType, Row]):
                 pgq.dump(params)
 
             results = yield from self._maybe_prepare_gen(pgq, prepare=True)
-            self._set_results(results)
+            self._check_results(results)
 
             for res in results:
                 nrows += res.command_tuples or 0
@@ -398,9 +399,12 @@ class BaseCursor(Generic[ConnectionType, Row]):
         ExecStatus.COPY_BOTH,
     )
 
-    def _set_results(self, results: List["PGresult"]) -> None:
+    def _check_results(self, results: List["PGresult"]) -> None:
         """
-        Set the results from a query into the cursor state.
+        Verify that the results of a query are valid.
+
+        Verify that the query returned at least one result and that they all
+        represent a valid result from the database.
         """
         if not results:
             raise e.InternalError("got no result from the query")
@@ -409,8 +413,6 @@ class BaseCursor(Generic[ConnectionType, Row]):
             if res.status not in self._status_ok:
                 self._raise_from_results(results)
 
-        self._results = results
-
     def _set_result(self, i: int, format: Optional[Format] = None) -> None:
         """
         Select one of the results in the cursor as the active one.
index ba6a62d4cbd84f4c68451b56ef1cf27de05f8e39..b769918cee7b49680bdf82df92f63b3aa32a7e17 100644 (file)
@@ -87,7 +87,8 @@ class ServerCursorHelper(Generic[ConnectionType, Row]):
         conn = cur._conn
         conn.pgconn.send_describe_portal(self.name.encode(cur._encoding))
         results = yield from execute(conn.pgconn)
-        cur._set_results(results)
+        cur._check_results(results)
+        cur._results = results
         cur._set_result(0, format=self._format)
         self.described = True