Add ability to force libpq to negotiate a specific version of the protocol.
authorAndres Freund <[email protected]>
Wed, 20 Sep 2017 08:12:32 +0000 (01:12 -0700)
committerAndres Freund <[email protected]>
Sun, 8 Oct 2017 16:41:55 +0000 (09:41 -0700)
Author: Andres Freund
Discussion: https://postgr.es/m/20170918095303[email protected]

src/interfaces/libpq/fe-connect.c
src/interfaces/libpq/libpq-int.h

index 5f79803607156d1777a23f025c88476b533f9021..b4d57d9d45831048f082b8bc0553e903fe6c0bb7 100644 (file)
@@ -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;
 
index 42913604e3969c8ece18e2160f0242e97ebace5d..7bfc09ec7119ccb1cb1a6dcad5f5b3d2a325403c 100644 (file)
@@ -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;