]> granicus.if.org Git - postgis/commitdiff
Logic to add topology to database search path on install or upgrade
authorRegina Obe <lr@pcorp.us>
Mon, 21 Nov 2011 07:48:23 +0000 (07:48 +0000)
committerRegina Obe <lr@pcorp.us>
Mon, 21 Nov 2011 07:48:23 +0000 (07:48 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@8197 b70326c6-7e19-0410-871a-916f4a2858ee

topology/sql/manage/ManageHelper.sql [new file with mode: 0644]
topology/topology.sql.in.c

diff --git a/topology/sql/manage/ManageHelper.sql b/topology/sql/manage/ManageHelper.sql
new file mode 100644 (file)
index 0000000..6950c25
--- /dev/null
@@ -0,0 +1,41 @@
+-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+-- 
+-- PostGIS - Spatial Types for PostgreSQL
+-- http://www.postgis.org
+--
+-- Copyright (C) 2011 Regina Obe <lr@pcorp.us>
+--
+-- 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
index 1261e06bb8466292e291c15857976194f290679d..4fc82d49c09b373747910af4eb7a459907155ce6 100644 (file)
@@ -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');