]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
feat(capabilities): add has_send_close_prepared()
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Mon, 10 Jun 2024 14:40:27 +0000 (16:40 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Thu, 13 Jun 2024 21:04:17 +0000 (23:04 +0200)
docs/api/objects.rst
psycopg/psycopg/_capabilities.py
psycopg/psycopg/_connection_base.py
tests/test_capabilities.py

index a94f08b5ba1abb73fb98d971fa89cf99f209d781..b79c5833d01ab5ec9a9767d513b9e04c57be2e4f 100644 (file)
@@ -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`
index 2af756330458072041f377c85a153d423c048faa..3ab7fd41546989d8da18407c25eb16f2c2ba136a 100644 (file)
@@ -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.
 
index 2d910aaa14107432523efc9c522d812ef7f13cfa..5741b849f1f5ff30719b100e5590464c96c6eb0b 100644 (file)
@@ -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")
 
index 6f2c8fce92501cf8e7d3996ac7ad768e0c4f834d..17fb96560827f2b741025e993a6eb18c32734be3 100644 (file)
@@ -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),
 ]