From cdb6b0fdb0b2face270406905d31f8f513b015cc Mon Sep 17 00:00:00 2001 From: Robert Haas Date: Mon, 9 Sep 2024 11:54:55 -0400 Subject: Add PQfullProtocolVersion() to surface the precise protocol version. The existing function PQprotocolVersion() does not include the minor version of the protocol. In preparation for pending work that will bump that number for the first time, add a new function to provide it to clients that may care, using the (major * 10000 + minor) convention already used by PQserverVersion(). Jacob Champion based on earlier work by Jelte Fennema-Nio Discussion: http://postgr.es/m/CAOYmi+mM8+6Swt1k7XsLcichJv8xdhPnuNv7-02zJWsezuDL+g@mail.gmail.com --- src/interfaces/libpq/fe-connect.c | 10 ++++++++++ src/interfaces/libpq/libpq-fe.h | 5 +++++ 2 files changed, 15 insertions(+) (limited to 'src/interfaces/libpq') diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c index 9febdaa2885..d5a72587d24 100644 --- a/src/interfaces/libpq/fe-connect.c +++ b/src/interfaces/libpq/fe-connect.c @@ -7158,6 +7158,16 @@ PQprotocolVersion(const PGconn *conn) return PG_PROTOCOL_MAJOR(conn->pversion); } +int +PQfullProtocolVersion(const PGconn *conn) +{ + if (!conn) + return 0; + if (conn->status == CONNECTION_BAD) + return 0; + return PG_PROTOCOL_FULL(conn->pversion); +} + int PQserverVersion(const PGconn *conn) { diff --git a/src/interfaces/libpq/libpq-fe.h b/src/interfaces/libpq/libpq-fe.h index ca3e028a512..15012c770c4 100644 --- a/src/interfaces/libpq/libpq-fe.h +++ b/src/interfaces/libpq/libpq-fe.h @@ -56,6 +56,10 @@ extern "C" /* Indicates presence of PQsocketPoll, PQgetCurrentTimeUSec */ #define LIBPQ_HAS_SOCKET_POLL 1 +/* Features added in PostgreSQL v18: */ +/* Indicates presence of PQfullProtocolVersion */ +#define LIBPQ_HAS_FULL_PROTOCOL_VERSION 1 + /* * Option flags for PQcopyResult */ @@ -393,6 +397,7 @@ extern PGTransactionStatusType PQtransactionStatus(const PGconn *conn); extern const char *PQparameterStatus(const PGconn *conn, const char *paramName); extern int PQprotocolVersion(const PGconn *conn); +extern int PQfullProtocolVersion(const PGconn *conn); extern int PQserverVersion(const PGconn *conn); extern char *PQerrorMessage(const PGconn *conn); extern int PQsocket(const PGconn *conn); -- cgit v1.2.3