From: Sandro Santilli Date: Fri, 4 Jun 2004 13:39:29 +0000 (+0000) Subject: Removed references to constraint name (unsafe) from probe_geometry_columns() X-Git-Tag: pgis_0_9_1~202 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e6b92aab1ebcde175ee3f8775788e9d31c007142;p=postgis Removed references to constraint name (unsafe) from probe_geometry_columns() 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 --- diff --git a/postgis.sql.in b/postgis.sql.in index 3f5593064..d650e8bd2 100644 --- a/postgis.sql.in +++ b/postgis.sql.in @@ -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';