]> granicus.if.org Git - postgis/commitdiff
Removed references to constraint name (unsafe) from probe_geometry_columns()
authorSandro Santilli <strk@keybit.net>
Fri, 4 Jun 2004 13:39:29 +0000 (13:39 +0000)
committerSandro Santilli <strk@keybit.net>
Fri, 4 Jun 2004 13:39:29 +0000 (13:39 +0000)
and fix_geometry_columns(). Added a rename_geometry_table_constraints()
renaming all geometry constraints to 'enforce_srid' and 'enforce_geotype'

git-svn-id: http://svn.osgeo.org/postgis/trunk@592 b70326c6-7e19-0410-871a-916f4a2858ee

postgis.sql.in

index 3f55930645ae1b27346a66c4ff007f36a666e3b4..d650e8bd279d422fb9ef84ad87a960fd921788b5 100644 (file)
@@ -347,6 +347,38 @@ CREATEFUNCTION get_proj4_from_srid(integer) RETURNS text AS
 LANGUAGE 'sql' WITH (iscachable,isstrict);
 
 
+-----------------------------------------------------------------------
+-- RENAME_GEOMETRY_TABLE_CONSTRAINTS()
+-----------------------------------------------------------------------
+-- Rename SRID checks to enforce_srid
+-- Rename TYPE checks to enforce_geotype
+-----------------------------------------------------------------------
+CREATEFUNCTION rename_geometry_table_constraints() RETURNS text
+AS 
+'
+DECLARE
+       fixed_srid integer;
+       fixed_type integer;
+BEGIN
+       UPDATE pg_constraint SET conname = ''enforce_geotype''
+       WHERE consrc like
+       ''((geometrytype(%) = ''''%''''::text) OR (% IS NULL))''
+       AND conname != ''enforce_geotype'';
+
+       GET DIAGNOSTICS fixed_type = ROW_COUNT;
+
+       UPDATE pg_constraint SET conname = ''enforce_srid''
+       WHERE consrc like
+       ''(srid(% = %)''
+       AND conname != ''enforce_srid'';
+
+       GET DIAGNOSTICS fixed_srid = ROW_COUNT;
+
+        RETURN ''fixed srid_checks:''||fixed_srid||
+               '' type_checks:''||fixed_type;
+END;
+' LANGUAGE 'plpgsql';
+
 -----------------------------------------------------------------------
 -- FIX_GEOMETRY_COLUMNS() 
 -----------------------------------------------------------------------
@@ -398,9 +430,12 @@ BEGIN
                 AND c.relnamespace = n.oid
                 AND f_geometry_column::name = a.attname
                 AND sridcheck.conrelid = c.oid
-                AND sridcheck.conname = ''$1''
+                --AND sridcheck.conname = ''$1''
+               AND sridcheck.consrc LIKE ''(srid(% = %)''
                 AND typecheck.conrelid = c.oid
-                AND typecheck.conname = ''$2''
+                --AND typecheck.conname = ''$2''
+               AND typecheck.consrc LIKE
+       ''((geometrytype(%) = ''''%''''::text) OR (% IS NULL))''
                 AND sridcheck.consrc ~ textcat('' = '', srid::text)
                 AND typecheck.consrc ~ textcat('' = '''''', type::text)
                 AND NOT EXISTS (
@@ -478,6 +513,7 @@ DECLARE
        inserted integer;
        oldcount integer;
        probed integer;
+       stale integer;
 BEGIN
 
        SELECT count(*) INTO oldcount FROM geometry_columns;
@@ -497,9 +533,13 @@ BEGIN
                AND typecheck.connamespace = n.oid
 #endif
                AND sridcheck.conrelid = c.oid
-               AND sridcheck.conname = ''$1''
+               --AND sridcheck.conname = ''$1''
+               AND sridcheck.consrc LIKE ''(srid(% = %)''
                AND typecheck.conrelid = c.oid
-               AND typecheck.conname = ''$2'';
+               --AND typecheck.conname = ''$2'';
+               AND typecheck.consrc LIKE
+       ''((geometrytype(%) = ''''%''''::text) OR (% IS NULL))''
+               ;
 
        INSERT INTO geometry_columns SELECT
                ''''::varchar as f_table_catalogue,
@@ -537,9 +577,12 @@ BEGIN
                AND typecheck.connamespace = n.oid
 #endif
                AND sridcheck.conrelid = c.oid
-               AND sridcheck.conname = ''$1''
+               --AND sridcheck.conname = ''$1''
+               AND sridcheck.consrc LIKE ''(srid(% = %)''
                AND typecheck.conrelid = c.oid
-               AND typecheck.conname = ''$2''
+               --AND typecheck.conname = ''$2''
+               AND typecheck.consrc LIKE
+       ''((geometrytype(%) = ''''%''''::text) OR (% IS NULL))''
 
                 AND NOT EXISTS (
                         SELECT oid FROM geometry_columns gc
@@ -552,10 +595,16 @@ BEGIN
 
        GET DIAGNOSTICS inserted = ROW_COUNT;
 
+       IF oldcount > probed THEN
+               stale = oldcount-probed;
+       ELSE
+               stale = 0;
+       END IF;
+
         RETURN ''probed:''||probed||
                '' inserted:''||inserted||
                '' conflicts:''||probed-inserted||
-               '' stale:''||oldcount-probed;
+               '' stale:''||stale;
 END
 
 ' LANGUAGE 'plpgsql';