From 243df1584e46c6bec096bd6880aa30d9627e33e3 Mon Sep 17 00:00:00 2001 From: Regina Obe Date: Mon, 21 Nov 2011 07:48:23 +0000 Subject: [PATCH] Logic to add topology to database search path on install or upgrade git-svn-id: http://svn.osgeo.org/postgis/trunk@8197 b70326c6-7e19-0410-871a-916f4a2858ee --- topology/sql/manage/ManageHelper.sql | 41 ++++++++++++++++++++++++++++ topology/topology.sql.in.c | 5 +++- 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 topology/sql/manage/ManageHelper.sql diff --git a/topology/sql/manage/ManageHelper.sql b/topology/sql/manage/ManageHelper.sql new file mode 100644 index 000000000..6950c25cb --- /dev/null +++ b/topology/sql/manage/ManageHelper.sql @@ -0,0 +1,41 @@ +-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +-- +-- PostGIS - Spatial Types for PostgreSQL +-- http://www.postgis.org +-- +-- Copyright (C) 2011 Regina Obe +-- +-- This is free software; you can redistribute and/or modify it under +-- the terms of the GNU General Public Licence. See the COPYING file. +-- +-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +--{ +-- AddToSearchPath(schema_name) +-- +-- Adds the specified schema to the database search path +-- if it is not already in the database search path +-- This is a helper function for upgrade/install +-- We may want to move this function as a generic helper +CREATE OR REPLACE FUNCTION topology.AddToSearchPath(a_schema_name varchar) +RETURNS text +AS +$$ +DECLARE + var_result text; + var_cur_search_path text; +BEGIN + SELECT reset_val INTO var_cur_search_path FROM pg_settings WHERE name = 'search_path'; + IF var_cur_search_path LIKE '%' || quote_literal(a_schema_name) || '%' THEN + var_result := a_schema_name || ' already in database search_path'; + ELSE + EXECUTE 'ALTER DATABASE ' || current_database() || ' SET search_path = ' || var_cur_search_path || ', ' || quote_ident(a_schema_name); + var_result := a_schema_name || ' has been added to end of database search_path '; + END IF; + + RETURN var_result; +END +$$ +LANGUAGE 'plpgsql' VOLATILE STRICT; + +--} AddToSearchPath diff --git a/topology/topology.sql.in.c b/topology/topology.sql.in.c index 1261e06bb..4fc82d49c 100644 --- a/topology/topology.sql.in.c +++ b/topology/topology.sql.in.c @@ -2462,6 +2462,9 @@ LANGUAGE 'plpgsql' VOLATILE STRICT; -- The following file needs getfaceedges_returntype, defined in sqlmm.sql #include "sql/query/GetRingEdges.sql" +--general management -- +#include "sql/manage/ManageHelper.sql" --COMMIT; - +-- Make sure topology is in database search path -- +SELECT topology.AddToSearchPath('topology'); -- 2.50.0