]> 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:58:08 +0000 (20:58 +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 fb71d9d51808e40c123acb570774c932ff377768..30a47448443d1282ffb615fefcba9d19d57ea3d8 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
 
@@ -217,7 +218,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
@@ -391,9 +392,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")
@@ -402,8 +406,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