From: Sandro Santilli Date: Wed, 13 Mar 2019 15:10:40 +0000 (+0000) Subject: Refuse to load PostGIS in an untargeted PostgreSQL version X-Git-Tag: 3.0.0alpha1~90 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4fc5b6645305ae6b772042f30110c66a1b2fe08f;p=postgis Refuse to load PostGIS in an untargeted PostgreSQL version Helps user finding out what problems they have when this happens git-svn-id: http://svn.osgeo.org/postgis/trunk@17341 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/configure.ac b/configure.ac index 9cfd44a3c..65437c008 100644 --- a/configure.ac +++ b/configure.ac @@ -466,6 +466,7 @@ if test "x$LIBLWGEOM_ONLY" = "xno"; then fi POSTGIS_PGSQL_VERSION="$PGSQL_MAJOR_VERSION$PGSQL_MINOR_VERSION" + POSTGIS_PGSQL_HR_VERSION="$PGSQL_MAJOR_VERSION.$PGSQL_MINOR_VERSION" PGSQL_PKGLIBDIR=`"$PG_CONFIG" --pkglibdir` PGSQL_LIBDIR=`"$PG_CONFIG" --libdir` @@ -550,6 +551,8 @@ if test "x$LIBLWGEOM_ONLY" = "xno"; then AC_DEFINE_UNQUOTED([POSTGIS_PGSQL_VERSION], [$POSTGIS_PGSQL_VERSION], [PostgreSQL server version]) AC_SUBST([POSTGIS_PGSQL_VERSION]) + AC_DEFINE_UNQUOTED([POSTGIS_PGSQL_HR_VERSION], [$POSTGIS_PGSQL_HR_VERSION], [PostgreSQL human readable server version]) + AC_SUBST([POSTGIS_PGSQL_HR_VERSION]) AC_SUBST([HAVE_SPGIST]) fi dnl LIBLWGEOM_ONLY != no diff --git a/postgis/postgis.sql.in b/postgis/postgis.sql.in index 1013e3c0b..f887757c1 100644 --- a/postgis/postgis.sql.in +++ b/postgis/postgis.sql.in @@ -25,6 +25,27 @@ BEGIN; SET LOCAL client_min_messages TO warning; +DO $$ +DECLARE + pgver text; +BEGIN + SELECT substring(version(), 'PostgreSQL ([0-9\.]+)') INTO pgver; + + IF POSTGIS_PGSQL_VERSION::text != ( SELECT CASE + WHEN split_part(s,'.',1)::integer > 9 + THEN split_part(s,'.',1) || '0' + ELSE + split_part(s,'.', 1) || split_part(s,'.', 2) + END + FROM substring(version(), 'PostgreSQL ([0-9\.]+)') AS s ) + THEN + RAISE EXCEPTION 'PostGIS built for PostgreSQL % cannot be loaded in PostgreSQL %', + POSTGIS_PGSQL_HR_VERSION, pgver; + END IF; +END; +$$; + + -- Check that no other postgis is installed DO $$ DECLARE @@ -2952,7 +2973,7 @@ BEGIN fullver = fullver || ' PGSQL="' || pgsql_scr_ver || '"'; IF pgsql_scr_ver != pgsql_ver THEN - fullver = fullver || ' (procs need upgrade for use with "' || pgsql_ver || '")'; + fullver = fullver || ' (procs need upgrade for use with PostgreSQL "' || pgsql_ver || '")'; END IF; IF geosver IS NOT NULL THEN diff --git a/postgis/sqldefines.h.in b/postgis/sqldefines.h.in index 9e5a3d63b..3a474a064 100644 --- a/postgis/sqldefines.h.in +++ b/postgis/sqldefines.h.in @@ -7,6 +7,7 @@ * Define just the version numbers; otherwise we get some strange substitutions in postgis.sql.in */ #define POSTGIS_PGSQL_VERSION @POSTGIS_PGSQL_VERSION@ +#define POSTGIS_PGSQL_HR_VERSION @POSTGIS_PGSQL_HR_VERSION@ #define POSTGIS_GEOS_VERSION @POSTGIS_GEOS_VERSION@ #define POSTGIS_PROJ_VERSION @POSTGIS_PROJ_VERSION@ #define POSTGIS_LIB_VERSION '@POSTGIS_LIB_VERSION@'