MCPcopy Create free account
hub / github.com/MapServer/MapServer / msPostGISRetrievePgVersion

Function msPostGISRetrievePgVersion

mappostgis.c:955–1004  ·  view source on GitHub ↗

** Recent versions of PgSQL provide the version as an int in a ** simple call to the connection handle. For earlier ones we have ** to parse the version string into a usable number. */

Source from the content-addressed store, hash-verified

953** to parse the version string into a usable number.
954*/
955static int
956msPostGISRetrievePgVersion(PGconn *pgconn) {
957#ifndef POSTGIS_HAS_SERVER_VERSION
958 int pgVersion = 0;
959 char *strVersion = NULL;
960 char *strParts[3] = { NULL, NULL, NULL };
961 int i = 0, j = 0, len = 0;
962 int factor = 10000;
963
964 if (pgconn == NULL) {
965 msSetError(MS_QUERYERR, "Layer does not have a postgis connection.", "msPostGISRetrievePgVersion()");
966 return MS_FAILURE;
967 }
968
969 if (! PQparameterStatus(pgconn, "server_version") )
970 return MS_FAILURE;
971
972 strVersion = msStrdup(PQparameterStatus(pgconn, "server_version"));
973 if( ! strVersion )
974 return MS_FAILURE;
975
976 strParts[j] = strVersion;
977 j++;
978 len = strlen(strVersion);
979 for( i = 0; i < len; i++ ) {
980 if( strVersion[i] == '.' ) {
981 strVersion[i] = '\0';
982
983 if( j < 3 ) {
984 strParts[j] = strVersion + i + 1;
985 j++;
986 }
987 else {
988 free(strVersion);
989 msSetError(MS_QUERYERR, "Too many parts in version string.", "msPostGISRetrievePgVersion()");
990 return MS_FAILURE;
991 }
992 }
993 }
994
995 for( j = 0; j < 3 && strParts[j]; j++ ) {
996 pgVersion += factor * atoi(strParts[j]);
997 factor = factor / 100;
998 }
999 free(strVersion);
1000 return pgVersion;
1001#else
1002 return PQserverVersion(pgconn);
1003#endif
1004}
1005
1006/*
1007** Get the PostGIS version number from the database as integer.

Callers 1

msPostGISRetrievePKFunction · 0.85

Calls 2

msSetErrorFunction · 0.85
msStrdupFunction · 0.85

Tested by

no test coverage detected