diff options
author | Robert Haas <rhaas@postgresql.org> | 2024-09-09 11:54:55 -0400 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2024-09-09 11:54:55 -0400 |
commit | cdb6b0fdb0b2face270406905d31f8f513b015cc (patch) | |
tree | 855c93a72bbe36872fa0f768a496f1749d030c75 /src | |
parent | 5bbdfa8a18dc56d3e64aa723a68e02e897cb5ec3 (diff) | |
download | postgresql-cdb6b0fdb0b2face270406905d31f8f513b015cc.tar.gz postgresql-cdb6b0fdb0b2face270406905d31f8f513b015cc.zip |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/include/libpq/pqcomm.h | 1 | ||||
-rw-r--r-- | src/interfaces/libpq/fe-connect.c | 10 | ||||
-rw-r--r-- | src/interfaces/libpq/libpq-fe.h | 5 |
3 files changed, 16 insertions, 0 deletions
diff --git a/src/include/libpq/pqcomm.h b/src/include/libpq/pqcomm.h index 527735e3dba..6925f10602b 100644 --- a/src/include/libpq/pqcomm.h +++ b/src/include/libpq/pqcomm.h @@ -86,6 +86,7 @@ is_unixsock_path(const char *path) #define PG_PROTOCOL_MAJOR(v) ((v) >> 16) #define PG_PROTOCOL_MINOR(v) ((v) & 0x0000ffff) +#define PG_PROTOCOL_FULL(v) (PG_PROTOCOL_MAJOR(v) * 10000 + PG_PROTOCOL_MINOR(v)) #define PG_PROTOCOL(m,n) (((m) << 16) | (n)) /* 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 @@ -7159,6 +7159,16 @@ PQprotocolVersion(const PGconn *conn) } 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) { if (!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); |