FindPostgreSQL: support version encoding used in pre-10 releases

With the 10.x release, PostgreSQL upstream started encoding the version
as `MMmmmm` where `M` is major and `m` is minor. Prior to that, `MMmmPP`
was used where `P` was the patch number. Detect this difference and
decode it based on the used encoding.

Fixes: #19912
This commit is contained in:
Ben Boeckel
2019-11-04 16:37:06 -05:00
parent c1d5d5eb11
commit e992d62b7e
2 changed files with 28 additions and 8 deletions
+12 -3
View File
@@ -5,10 +5,19 @@
int main()
{
int version = PQlibVersion();
int major = version / 10000;
int minor = version % 10000;
char version_string[100];
snprintf(version_string, sizeof(version_string), "%d.%d", major, minor);
// 9.x and older encoding.
if (version < 100000) {
int major = version / 10000;
int minor = version % 10000 / 100;
int patch = version % 100;
snprintf(version_string, sizeof(version_string), "%d.%d.%d", major, minor,
patch);
} else {
int major = version / 10000;
int minor = version % 10000;
snprintf(version_string, sizeof(version_string), "%d.%d", major, minor);
}
printf("Found PostgreSQL version %s, expected version %s\n", version_string,
CMAKE_EXPECTED_POSTGRESQL_VERSION);
return strcmp(version_string, CMAKE_EXPECTED_POSTGRESQL_VERSION);