Wrap libpq 18 PQfullProtocolVersion functions.
See #1079
autodoc_member_order = "bysource"
# PostgreSQL docs version to link libpq functions to
-libpq_docs_version = "17"
+libpq_docs_version = "18"
# Where to point on :ticket: role
ticket_url = "https://github.com/psycopg/psycopg/issues/%s"
- Add `pq.PGconn.used_gssapi` attribute and `Capabilities.has_used_gssapi()`
function (:ticket:`#1138`).
+- Add support for the :pq:`PQfullProtocolVersion()` function, introduced in
+ libpq v18 (:ticket:`#1079`).
.. rubric:: Other changes
error_message: bytes = b""
_encoding: str = "utf-8"
protocol_version: int = 0
+ full_protocol_version: int = 0
server_version: int = 0
backend_pid: int = 0
fdopen.argtypes = (c_int, c_char_p)
fdopen.restype = FILE_ptr
+
+def not_supported_before(fname: str, pgversion: int) -> Any:
+ def not_supported(*args: Any, **kwargs: Any) -> NoReturn:
+ raise NotSupportedError(
+ f"{fname} requires libpq from PostgreSQL {version_pretty(pgversion)} on"
+ f" the client; version {version_pretty(libpq_version)} available instead"
+ )
+
+ return not_supported
+
+
# Get the libpq version to define what functions are available.
PQlibVersion = pq.PQlibVersion
PQhost.restype = c_char_p
-def not_supported_before(fname: str, pgversion: int) -> Any:
- def not_supported(*args: Any, **kwargs: Any) -> NoReturn:
- raise NotSupportedError(
- f"{fname} requires libpq from PostgreSQL {version_pretty(pgversion)} on"
- f" the client; version {version_pretty(libpq_version)} available instead"
- )
-
- return not_supported
-
-
if libpq_version >= 120000:
PQhostaddr = pq.PQhostaddr
PQhostaddr.argtypes = [PGconn_ptr]
PQprotocolVersion.argtypes = [PGconn_ptr]
PQprotocolVersion.restype = c_int
+if libpq_version >= 180000:
+ PQfullProtocolVersion = pq.PQfullProtocolVersion
+ PQfullProtocolVersion.argtypes = [PGconn_ptr]
+ PQfullProtocolVersion.restype = c_int
+else:
+ PQfullProtocolVersion = not_supported_before("PQfullProtocolVersion", 180000)
+
PQserverVersion = pq.PQserverVersion
PQserverVersion.argtypes = [PGconn_ptr]
PQserverVersion.restype = c_int
def PQtransactionStatus(arg1: PGconn_struct | None) -> int: ...
def PQparameterStatus(arg1: PGconn_struct | None, arg2: bytes) -> bytes | None: ...
def PQprotocolVersion(arg1: PGconn_struct | None) -> int: ...
+def PQfullProtocolVersion(arg1: PGconn_struct | None) -> int: ...
def PQserverVersion(arg1: PGconn_struct | None) -> int: ...
def PQsocket(arg1: PGconn_struct | None) -> int: ...
def PQbackendPID(arg1: PGconn_struct | None) -> int: ...
@property
def protocol_version(self) -> int: ...
+ @property
+ def full_protocol_version(self) -> int: ...
+
@property
def server_version(self) -> int: ...
def protocol_version(self) -> int:
return self._call_int(impl.PQprotocolVersion)
+ @property
+ def full_protocol_version(self) -> int:
+ return self._call_int(impl.PQfullProtocolVersion)
+
@property
def server_version(self) -> int:
return self._call_int(impl.PQserverVersion)
PGTransactionStatusType PQtransactionStatus(const PGconn *conn)
const char *PQparameterStatus(const PGconn *conn, const char *paramName)
int PQprotocolVersion(const PGconn *conn)
+ int PQfullProtocolVersion(const PGconn *conn)
int PQserverVersion(const PGconn *conn)
char *PQerrorMessage(const PGconn *conn)
int PQsocket(const PGconn *conn) nogil
#define PQcancelFinish(cancelConn) 0
#define PQsetChunkedRowsMode(conn, chunkSize) 0
#endif
+
+#if PG_VERSION_NUM < 180000
+#define PQfullProtocolVersion(conn) 0
+#endif
"""
def protocol_version(self) -> int:
return _call_int(self, libpq.PQprotocolVersion)
+ @property
+ def full_protocol_version(self) -> int:
+ _check_supported("PQfullProtocolVersion", 180000)
+ _ensure_pgconn(self)
+ return libpq.PQfullProtocolVersion(self._pgconn_ptr)
+
@property
def server_version(self) -> int:
return _call_int(self, libpq.PQserverVersion)
pgconn.protocol_version
+@pytest.mark.libpq(">= 18")
+def test_full_protocol_version(pgconn):
+ assert pgconn.full_protocol_version >= 30000
+ pgconn.finish()
+ with pytest.raises(psycopg.OperationalError):
+ pgconn.full_protocol_version
+
+
+@pytest.mark.libpq("< 18")
+def test_full_protocol_version_notimpl(pgconn):
+ with pytest.raises(psycopg.NotSupportedError):
+ pgconn.full_protocol_version
+
+
def test_server_version(pgconn):
assert pgconn.server_version >= 90400
pgconn.finish()