From: Daniele Varrazzo Date: Wed, 8 Jun 2022 15:28:43 +0000 (+0200) Subject: refactor: rename the no_pqexec param to force_extended X-Git-Tag: 3.1~63 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=13fc286c88cb434d031196a33b8f0798fd6507ec;p=thirdparty%2Fpsycopg.git refactor: rename the no_pqexec param to force_extended 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. --- diff --git a/psycopg/psycopg/client_cursor.py b/psycopg/psycopg/client_cursor.py index 2a1ce3078..6271ec508 100644 --- a/psycopg/psycopg/client_cursor.py +++ b/psycopg/psycopg/client_cursor.py @@ -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( diff --git a/psycopg/psycopg/cursor.py b/psycopg/psycopg/cursor.py index a12911941..18cc9d223 100644 --- a/psycopg/psycopg/cursor.py +++ b/psycopg/psycopg/cursor.py @@ -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( diff --git a/psycopg/psycopg/server_cursor.py b/psycopg/psycopg/server_cursor.py index 53585b49b..564392639 100644 --- a/psycopg/psycopg/server_cursor.py +++ b/psycopg/psycopg/server_cursor.py @@ -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])