]> granicus.if.org Git - postgis/commitdiff
AddTopoGeometryColumn: check child layer before incrementing sequence
authorSandro Santilli <strk@keybit.net>
Sun, 22 Jan 2012 19:25:24 +0000 (19:25 +0000)
committerSandro Santilli <strk@keybit.net>
Sun, 22 Jan 2012 19:25:24 +0000 (19:25 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@8902 b70326c6-7e19-0410-871a-916f4a2858ee

topology/test/regress/addtopogeometrycolumn.sql
topology/test/regress/addtopogeometrycolumn_expected
topology/topology.sql.in.c

index c1606ace847d41f07db5b8a34d5a02059bdd42eb..745f5d98152ad018a9d5965dcef90464d626aa3b 100644 (file)
@@ -5,6 +5,7 @@ select createtopology('tt') > 0;
 select addtopogeometrycolumn('tt','public','feature','tg','POINT'); -- fail
 create table feature(id integer);
 select addtopogeometrycolumn('tt','public','feature','tg','BOGUS'); -- fail
+select addtopogeometrycolumn('tt','public','feature','tg','POINT', 0); -- fail
 
 -- Expect first good call returning 1
 select 'good', addtopogeometrycolumn('tt','public','feature','tg','POINT');
index 9f67abeeec32cf6c044b83b6df86318988aaa77a..e20690d1131b31af055eefacf713d36915b087f5 100644 (file)
@@ -1,6 +1,7 @@
 t
 ERROR:  relation "public.feature" does not exist
 ERROR:  Layer type must be one of POINT,LINE,POLYGON,COLLECTION
+ERROR:  Child layer 0 does not exist in topology "tt"
 good|1
 1|public|feature|tg|1|0|
 Topology 'tt' dropped
index ea4256f911b527697cb0e4648e2c44f932af622a..aadb91509c5eee40cdef514fbd28e94c25c5e3a5 100644 (file)
@@ -581,6 +581,18 @@ BEGIN
                || ' topology.TopoGeometry;';
 
 
+       --
+       -- See if child id exists and extract its level
+       --
+       IF child IS NOT NULL THEN
+               SELECT level + 1 FROM topology.layer
+                       WHERE layer_id = child
+                       INTO level;
+               IF level IS NULL THEN
+                       RAISE EXCEPTION 'Child layer % does not exist in topology "%"', child, toponame;
+               END IF;
+       END IF;
+
        --
        -- Get new layer id from sequence
        --
@@ -589,41 +601,18 @@ BEGIN
                        quote_ident(toponame) || '.layer_id_seq'
                ) || ')' INTO STRICT layer_id;
 
-       --
-       -- See if child id exists and extract its level
-       --
-       IF child IS NULL THEN
-               EXECUTE 'INSERT INTO '
-                       || 'topology.layer(topology_id, '
-                       || 'layer_id, schema_name, '
-                       || 'table_name, feature_column, feature_type) '
-                       || 'VALUES ('
-                       || topoid || ','
-                       || layer_id || ',' 
-                       || quote_literal(schema) || ','
-                       || quote_literal(tbl) || ','
-                       || quote_literal(col) || ','
-                       || intltype || ');';
-       ELSE
-               FOR rec IN EXECUTE 'SELECT level FROM topology.layer'
-                       || ' WHERE layer_id = ' || child
-               LOOP
-                       level = rec.level + 1;
-               END LOOP;
-
-               EXECUTE 'INSERT INTO ' 
-                       || 'topology.layer(topology_id, '
-                       || 'layer_id, level, child_id, schema_name, '
-                       || 'table_name, feature_column, feature_type) '
-                       || 'VALUES ('
-                       || topoid || ','
-                       || layer_id || ',' || level || ','
-                       || child || ','
-                       || quote_literal(schema) || ','
-                       || quote_literal(tbl) || ','
-                       || quote_literal(col) || ','
-                       || intltype || ');';
-       END IF;
+       EXECUTE 'INSERT INTO ' 
+               || 'topology.layer(topology_id, '
+               || 'layer_id, level, child_id, schema_name, '
+               || 'table_name, feature_column, feature_type) '
+               || 'VALUES ('
+               || topoid || ','
+               || layer_id || ',' || COALESCE(level, 0) || ','
+               || COALESCE(child::text, 'NULL') || ','
+               || quote_literal(schema) || ','
+               || quote_literal(tbl) || ','
+               || quote_literal(col) || ','
+               || intltype || ');';
 
 
        --