From: Daniele Varrazzo Date: Mon, 10 Jun 2024 14:40:27 +0000 (+0200) Subject: feat(capabilities): add has_send_close_prepared() X-Git-Tag: 3.2.0~11^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c832254503d3af82fc8d3cadda85d20f795549a1;p=thirdparty%2Fpsycopg.git feat(capabilities): add has_send_close_prepared() --- diff --git a/docs/api/objects.rst b/docs/api/objects.rst index a94f08b5b..b79c5833d 100644 --- a/docs/api/objects.rst +++ b/docs/api/objects.rst @@ -158,6 +158,7 @@ Libpq capabilities information the legacy :pq:`PQcancel` implementation. .. automethod:: has_stream_chunked + .. automethod:: has_send_close_prepared .. automethod:: has_pgbouncer_prepared .. seealso:: :ref:`pgbouncer` diff --git a/psycopg/psycopg/_capabilities.py b/psycopg/psycopg/_capabilities.py index 2af756330..3ab7fd415 100644 --- a/psycopg/psycopg/_capabilities.py +++ b/psycopg/psycopg/_capabilities.py @@ -64,6 +64,13 @@ class Capabilities: "Cursor.stream() with 'size' parameter greater than 1", 170000, check=check ) + def has_send_close_prepared(self, check: bool = False) -> bool: + """Check if the `pq.PGconn.send_closed_prepared()` method is implemented. + + The feature requires libpq 17.0 and greater. + """ + return self._has_feature("PGconn.send_close_prepared()", 170000, check=check) + def has_pgbouncer_prepared(self, check: bool = False) -> bool: """Check if prepared statements in PgBouncer are supported. diff --git a/psycopg/psycopg/_connection_base.py b/psycopg/psycopg/_connection_base.py index 2d910aaa1..5741b849f 100644 --- a/psycopg/psycopg/_connection_base.py +++ b/psycopg/psycopg/_connection_base.py @@ -27,6 +27,7 @@ from ._compat import LiteralString, Self, TypeAlias, TypeVar from .pq.misc import connection_summary from ._pipeline import BasePipeline from ._preparing import PrepareManager +from ._capabilities import capabilities from ._connection_info import ConnectionInfo if TYPE_CHECKING: @@ -50,7 +51,7 @@ FATAL_ERROR = pq.ExecStatus.FATAL_ERROR IDLE = pq.TransactionStatus.IDLE INTRANS = pq.TransactionStatus.INTRANS -_HAS_SEND_CLOSE = pq.__build_version__ >= 170000 +_HAS_SEND_CLOSE = capabilities.has_send_close_prepared() logger = logging.getLogger("psycopg") diff --git a/tests/test_capabilities.py b/tests/test_capabilities.py index 6f2c8fce9..17fb96560 100644 --- a/tests/test_capabilities.py +++ b/tests/test_capabilities.py @@ -17,6 +17,7 @@ caps = [ ("has_set_trace_flags", "PGconn.set_trace_flags()", 14), ("has_cancel_safe", "Connection.cancel_safe()", 17), ("has_stream_chunked", "Cursor.stream() with 'size' parameter greater than 1", 17), + ("has_send_close_prepared", "PGconn.send_close_prepared()", 17), ("has_pgbouncer_prepared", "PgBouncer prepared statements compatibility", 17), ]