]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
refactor: rename the no_pqexec param to force_extended
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Wed, 8 Jun 2022 15:28:43 +0000 (17:28 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Wed, 8 Jun 2022 15:32:06 +0000 (17:32 +0200)
This refers to using the extended query protocol even in cases where the
singe query protocol might have been chosen instead (e.g. because we
don't have parameters to send).

The negative in the param name is confusing, and the reference to the
PQexec function is wrong, because we never use that function (which is
blocking), but rather we choose PQsendQueryParams instead of
PQsendQuery.

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

index 2a1ce3078c7602bbf3747bab7330da48aea25360..6271ec5086554038cf72566c3b5c6c73a16685da 100644 (file)
@@ -44,7 +44,7 @@ class ClientCursorMixin(BaseCursor[ConnectionType, Row]):
         self,
         query: PostgresQuery,
         *,
-        no_pqexec: bool = False,
+        force_extended: bool = False,
         binary: Optional[bool] = None,
     ) -> None:
         if binary is None:
@@ -65,11 +65,11 @@ class ClientCursorMixin(BaseCursor[ConnectionType, Row]):
             self._conn._pipeline.command_queue.append(
                 partial(self._pgconn.send_query_params, query.query, None)
             )
-        elif no_pqexec:
+        elif force_extended:
             self._pgconn.send_query_params(query.query, None)
         else:
-            # if we don't have to, let's use exec_ as it can run more than
-            # one query in one go
+            # If we can, let's use simple query protocol,
+            # as it can execute more than one statement in a single query.
             self._pgconn.send_query(query.query)
 
     def _convert_query(
index a129119412a71a94ed8f31ad2ccfdcd9c46c0fc1..18cc9d2230ce29687283c53eaa098579a7a089c7 100644 (file)
@@ -352,7 +352,7 @@ class BaseCursor(Generic[ConnectionType, Row]):
         """Generator to send the query for `Cursor.stream()`."""
         yield from self._start_query(query)
         pgq = self._convert_query(query, params)
-        self._execute_send(pgq, binary=binary, no_pqexec=True)
+        self._execute_send(pgq, binary=binary, force_extended=True)
         self._pgconn.set_single_row_mode()
         self._last_query = query
         yield from send(self._pgconn)
@@ -434,7 +434,7 @@ class BaseCursor(Generic[ConnectionType, Row]):
         self,
         query: PostgresQuery,
         *,
-        no_pqexec: bool = False,
+        force_extended: bool = False,
         binary: Optional[bool] = None,
     ) -> None:
         """
@@ -462,7 +462,7 @@ class BaseCursor(Generic[ConnectionType, Row]):
                     result_format=fmt,
                 )
             )
-        elif no_pqexec or query.params or fmt == BINARY:
+        elif force_extended or query.params or fmt == BINARY:
             self._pgconn.send_query_params(
                 query.query,
                 query.params,
@@ -471,8 +471,8 @@ class BaseCursor(Generic[ConnectionType, Row]):
                 result_format=fmt,
             )
         else:
-            # if we don't have to, let's use exec_ as it can run more than
-            # one query in one go
+            # If we can, let's use simple query protocol,
+            # as it can execute more than one statement in a single query.
             self._pgconn.send_query(query.query)
 
     def _convert_query(
index 53585b49b409fe6289cd592253b3bf338579e751..564392639f8a4fe9aee17aeb48e0784fb163c875 100644 (file)
@@ -94,7 +94,7 @@ class ServerCursorMixin(BaseCursor[ConnectionType, Row]):
 
         yield from self._start_query(query)
         pgq = self._convert_query(query, params)
-        self._execute_send(pgq, no_pqexec=True)
+        self._execute_send(pgq, force_extended=True)
         results = yield from execute(self._conn.pgconn)
         if results[-1].status != COMMAND_OK:
             self._raise_for_result(results[-1])