Provide feature-test macros for libpq features added in v14.

We had a request to provide a way to test at compile time for the
availability of the new pipeline features.  More generally, it
seems like a good idea to provide a way to test via #ifdef for
all new libpq API features.  People have been using the version
from pg_config.h for that; but that's more likely to represent the
server version than the libpq version, in the increasingly-common
scenario where they're different.  It's safer if libpq-fe.h itself
is the source of truth about what features it offers.

Hence, establish a policy that starting in v14 we'll add a suitable
feature-is-present macro to libpq-fe.h when we add new API there.
(There doesn't seem to be much point in applying this policy
retroactively, but it's not too late for v14.)

Tom Lane and Alvaro Herrera, per suggestion from Boris Kolpackov.

Discussion: https://postgr.es/m/boris.20210617102439@codesynthesis.com
This commit is contained in:
Tom Lane 2021-06-19 11:44:39 -04:00
parent 2731ce1bd5
commit 6991e774e0
1 changed files with 11 additions and 2 deletions

View File

@ -28,6 +28,15 @@ extern "C"
*/ */
#include "postgres_ext.h" #include "postgres_ext.h"
/*
* These symbols may be used in compile-time #ifdef tests for the availability
* of newer libpq features.
*/
/* Indicates presence of PQenterPipelineMode and friends */
#define LIBPQ_HAS_PIPELINING 1
/* Indicates presence of PQsetTraceFlags; also new PQtrace output format */
#define LIBPQ_HAS_TRACE_FLAGS 1
/* /*
* Option flags for PQcopyResult * Option flags for PQcopyResult
*/ */
@ -98,7 +107,7 @@ typedef enum
PGRES_COPY_BOTH, /* Copy In/Out data transfer in progress */ PGRES_COPY_BOTH, /* Copy In/Out data transfer in progress */
PGRES_SINGLE_TUPLE, /* single tuple from larger resultset */ PGRES_SINGLE_TUPLE, /* single tuple from larger resultset */
PGRES_PIPELINE_SYNC, /* pipeline synchronization point */ PGRES_PIPELINE_SYNC, /* pipeline synchronization point */
PGRES_PIPELINE_ABORTED, /* Command didn't run because of an abort PGRES_PIPELINE_ABORTED /* Command didn't run because of an abort
* earlier in a pipeline */ * earlier in a pipeline */
} ExecStatusType; } ExecStatusType;
@ -398,7 +407,7 @@ extern pgthreadlock_t PQregisterThreadLock(pgthreadlock_t newhandler);
extern void PQtrace(PGconn *conn, FILE *debug_port); extern void PQtrace(PGconn *conn, FILE *debug_port);
extern void PQuntrace(PGconn *conn); extern void PQuntrace(PGconn *conn);
/* flags controlling trace output */ /* flags controlling trace output: */
/* omit timestamps from each line */ /* omit timestamps from each line */
#define PQTRACE_SUPPRESS_TIMESTAMPS (1<<0) #define PQTRACE_SUPPRESS_TIMESTAMPS (1<<0)
/* redact portions of some messages, for testing frameworks */ /* redact portions of some messages, for testing frameworks */