From: Andres Freund Date: Wed, 20 Sep 2017 08:12:32 +0000 (-0700) Subject: Add ability to force libpq to negotiate a specific version of the protocol. X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=36bfaf50ff0bfac9eb45956912bb149093bbcd37;p=users%2Fandresfreund%2Fpostgres.git Add ability to force libpq to negotiate a specific version of the protocol. Author: Andres Freund Discussion: https://postgr.es/m/20170918095303.g766pdnvviqlewph@alap3.anarazel.de --- diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c index 5f79803607..b4d57d9d45 100644 --- a/src/interfaces/libpq/fe-connect.c +++ b/src/interfaces/libpq/fe-connect.c @@ -323,6 +323,10 @@ static const internalPQconninfoOption PQconninfoOptions[] = { "Target-Session-Attrs", "", 11, /* sizeof("read-write") = 11 */ offsetof(struct pg_conn, target_session_attrs)}, + {"forced_protocol_version", "PGFORCEPROTOCOLVERSION", NULL, NULL, + "Forced-version", "D", sizeof("Forced-version"), + offsetof(struct pg_conn, forced_protocol_version)}, + /* Terminating entry --- MUST BE LAST */ {NULL, NULL, NULL, NULL, NULL, NULL, 0} @@ -1803,7 +1807,14 @@ connectDBStart(PGconn *conn) */ conn->whichhost = 0; conn->addr_cur = conn->connhost[0].addrlist; - conn->pversion = PG_PROTOCOL(3, 0); + if (conn->forced_protocol_version != NULL) + { + conn->pversion = atoi(conn->forced_protocol_version); + } + else + { + conn->pversion = PG_PROTOCOL(3, 0); + } conn->send_appname = true; conn->status = CONNECTION_NEEDED; diff --git a/src/interfaces/libpq/libpq-int.h b/src/interfaces/libpq/libpq-int.h index 42913604e3..7bfc09ec71 100644 --- a/src/interfaces/libpq/libpq-int.h +++ b/src/interfaces/libpq/libpq-int.h @@ -364,6 +364,9 @@ struct pg_conn /* Type of connection to make. Possible values: any, read-write. */ char *target_session_attrs; + char *forced_protocol_version; /* for testing: force protocol to a + * specific version */ + /* Optional file to write trace info to */ FILE *Pfdebug;