Skip to content

Commit cae0d4f

Browse files
committed
Teach libpq to decode server version correctly from future servers.
Beginning with the next development cycle, PG servers will report two-part not three-part version numbers. Fix libpq so that it will compute the correct numeric representation of such server versions for reporting by PQserverVersion(). It's desirable to get this into the field and back-patched ASAP, so that older clients are more likely to understand the new server version numbering by the time any such servers are in the wild. (The results with an old client would probably not be catastrophic anyway for a released server; for example "10.1" would be interpreted as 100100 which would be wrong in detail but would not likely cause an old client to misbehave badly. But "10devel" or "10beta1" would result in sversion==0 which at best would result in disabling all use of modern features.) Extracted from a patch by Peter Eisentraut; comments added by me Patch: <802ec140-635d-ad86-5fdf-d3af0e260c22@2ndquadrant.com>
1 parent b07058c commit cae0d4f

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

src/interfaces/libpq/fe-exec.c

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -982,14 +982,31 @@ pqSaveParameterStatus(PGconn *conn, const char *name, const char *value)
982982

983983
cnt = sscanf(value, "%d.%d.%d", &vmaj, &vmin, &vrev);
984984

985-
if (cnt < 2)
986-
conn->sversion = 0; /* unknown */
987-
else
985+
if (cnt == 3)
988986
{
989-
if (cnt == 2)
990-
vrev = 0;
987+
/* old style, e.g. 9.6.1 */
991988
conn->sversion = (100 * vmaj + vmin) * 100 + vrev;
992989
}
990+
else if (cnt == 2)
991+
{
992+
if (vmaj >= 10)
993+
{
994+
/* new style, e.g. 10.1 */
995+
conn->sversion = 100 * 100 * vmaj + vmin;
996+
}
997+
else
998+
{
999+
/* old style without minor version, e.g. 9.6devel */
1000+
conn->sversion = (100 * vmaj + vmin) * 100;
1001+
}
1002+
}
1003+
else if (cnt == 1)
1004+
{
1005+
/* new style without minor version, e.g. 10devel */
1006+
conn->sversion = 100 * 100 * vmaj;
1007+
}
1008+
else
1009+
conn->sversion = 0; /* unknown */
9931010
}
9941011
}
9951012

0 commit comments

Comments
 (0)