-
Notifications
You must be signed in to change notification settings - Fork 7
/
XP_Basisschema.sql
executable file
·2852 lines (2605 loc) · 177 KB
/
XP_Basisschema.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- -----------------------------------------------------
-- XP__Basisschema
-- Das XPLanGML Basisschema enthält abstrakte Oberklassen, von denen alle Klassen der Fachschemata abgeleitet sind,
-- sowie allgemeine Feature-Types, DataTypes und Enumerationen, die in verschiedenen Fach-Schemata verwendet werden.
-- Version für PostGIS 2.*
-- -----------------------------------------------------
/* *************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
************************************************************************* */
-- *****************************************************
-- pgcrypto enthält einen uuid-Generator
-- *****************************************************
CREATE EXTENSION pgcrypto;
-- *****************************************************
-- CREATE SCHEMAS
-- *****************************************************
CREATE SCHEMA "XP_Basisobjekte";
CREATE SCHEMA "XP_Sonstiges";
CREATE SCHEMA "XP_Praesentationsobjekte";
CREATE SCHEMA "XP_Enumerationen";
CREATE SCHEMA "XP_Raster";
COMMENT ON SCHEMA "XP_Basisobjekte" IS 'Dieses Paket enthält die Basisklassen des XPlanGML Schemas.';
COMMENT ON SCHEMA "XP_Sonstiges" IS 'Allegemeine Datentypen.';
COMMENT ON SCHEMA "XP_Praesentationsobjekte" IS 'Das Paket Praesentationsobjekte modelliert Klassen, die lediglich der graphischen Ausgestaltung eines Plans dienen und selbst keine eigentlichen Plan-Inhalte repräsentieren. Die entsprechenden Fachobjekte können unmittelbar instanziiert werden.';
COMMENT ON SCHEMA "XP_Enumerationen" IS 'Dieses Paket enthält verschiedene Enumerationen, die Fachschema-übergreifend verwwendet werden';
COMMENT ON SCHEMA "XP_Raster" IS 'Dieses Paket enthält Basisklassen für die Rasterdarstellung von Bebauungsplänen, Flächennutzungsplänen, Landschafts- und Regionalplänen.';
GRANT USAGE ON SCHEMA "XP_Basisobjekte" TO xp_gast;
GRANT USAGE ON SCHEMA "XP_Sonstiges" TO xp_gast;
GRANT USAGE ON SCHEMA "XP_Praesentationsobjekte" TO xp_gast;
GRANT USAGE ON SCHEMA "XP_Enumerationen" TO xp_gast;
GRANT USAGE ON SCHEMA "XP_Raster" TO xp_gast;
-- *****************************************************
-- CREATE FUNCTIONs
-- *****************************************************
CREATE OR REPLACE FUNCTION "XP_Basisobjekte".ensure_sequence(name_of_schema character varying, name_of_table character varying, pk_column character varying)
RETURNS character varying AS
$BODY$
DECLARE
str_trigger varchar;
BEGIN
str_trigger := 'CREATE FUNCTION ' || quote_ident(name_of_schema) || '.' || quote_ident(name_of_table || '_ensure_sequence') ||
'() RETURNS TRIGGER AS $ensure_sequence$' || E'\n';
str_trigger := str_trigger || 'DECLARE' || E'\n';
str_trigger := str_trigger || ' str_execute text;' || E'\n';
str_trigger := str_trigger || 'BEGIN' || E'\n';
str_trigger := str_trigger || ' IF (TG_OP = ' || quote_literal('INSERT') || ') THEN' || E'\n';
str_trigger := str_trigger || ' NEW.' || pk_column || ' := nextval(' ||
quote_literal(quote_ident(name_of_schema) || '.' || quote_ident(name_of_table || '_' ||
pk_column || '_seq')) || ');' || E'\n';
str_trigger := str_trigger || ' ELSIF (TG_OP = ' || quote_literal('UPDATE') || ') THEN' || E'\n';
str_trigger := str_trigger || ' NEW.' || pk_column || ' := ' || 'OLD.' || pk_column || ';' || E'\n';
str_trigger := str_trigger || ' END IF;' || E'\n';
str_trigger := str_trigger || ' RETURN NEW;' || E'\n';
str_trigger := str_trigger || 'END; $ensure_sequence$ LANGUAGE plpgsql;' || E'\n';
EXECUTE str_trigger;
EXECUTE 'GRANT EXECUTE ON FUNCTION ' || quote_ident(name_of_schema) || '.' ||
quote_ident(name_of_table || '_ensure_sequence') || '() TO xp_user;';
EXECUTE 'ALTER FUNCTION ' || quote_ident(name_of_schema) || '.' || quote_ident(name_of_table || '_ensure_sequence') ||
'() OWNER TO xp_user;';
EXECUTE 'CREATE TRIGGER ' || quote_ident(name_of_table || '_ensure_sequence') || ' BEFORE INSERT OR UPDATE ON ' ||
quote_ident(name_of_schema) || '.' || quote_ident(name_of_table) ||
' FOR EACH ROW EXECUTE PROCEDURE ' || quote_ident(name_of_schema) || '.' ||
quote_ident(name_of_table || '_ensure_sequence') || '();';
RETURN 'OK'; --*/
END; $BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
COMMENT ON FUNCTION "XP_Basisobjekte".ensure_sequence(character varying, character varying, character varying) IS
'Erzeugt Trigger, die für das PK-Feld den nächsten Wert aus der Sequenz vergeben und sicherstellen, dass der PK-Wert
vom Nutzer nicht geändert werden kann.';
CREATE OR REPLACE FUNCTION "XP_Basisobjekte".create_uuid()
RETURNS character varying AS
$BODY$
BEGIN
return gen_random_uuid(); -- version 4 uuid
END;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
GRANT EXECUTE ON FUNCTION "XP_Basisobjekte".create_uuid() TO xp_user;
CREATE OR REPLACE FUNCTION "XP_Basisobjekte"."gehoertZuPlan"(nspname character varying, relname character varying, gid bigint)
RETURNS integer AS
$BODY$
DECLARE
retvalue integer;
BEGIN
EXECUTE 'SELECT b."gehoertZuPlan" FROM ' ||
quote_ident(nspname) || '.' || quote_ident(relname) || ' b ' ||
' WHERE b.gid = ' || CAST(gid as varchar) || ';' INTO retvalue;
RETURN retvalue;
END;
$BODY$
LANGUAGE plpgsql VOLATILE STRICT
COST 100;
GRANT EXECUTE ON FUNCTION "XP_Basisobjekte"."gehoertZuPlan"(character varying, character varying, bigint) TO xp_user;
COMMENT ON FUNCTION "XP_Basisobjekte"."gehoertZuPlan"(character varying, character varying, bigint) IS 'Gibt die gid des XP_Plans, zu dem ein XP_Bereich gehoert zurück';
CREATE OR REPLACE FUNCTION "XP_Basisobjekte"."XP_PO_artvalue"(nspname character varying, relname character varying, art character varying, gid bigint)
RETURNS character varying AS
$BODY$
DECLARE
retvalue character varying;
BEGIN
EXECUTE 'SELECT CAST(' || quote_ident(art) || ' as varchar) FROM ' ||
quote_ident(nspname) || '.' || quote_ident(relname) ||
' WHERE gid = ' || CAST(gid as varchar) || ';' INTO retvalue;
RETURN retvalue;
END;
$BODY$
LANGUAGE plpgsql VOLATILE STRICT
COST 100;
GRANT EXECUTE ON FUNCTION "XP_Basisobjekte"."XP_PO_artvalue"(character varying, character varying, character varying, bigint) TO xp_user;
COMMENT ON FUNCTION "XP_Basisobjekte"."XP_PO_artvalue"(character varying, character varying, character varying, bigint) IS 'gibt den Wert für das Feld art für gid in der relation nspname.relname aus';
-- *****************************************************
-- CREATE SEQUENCES
-- *****************************************************
CREATE SEQUENCE "XP_Basisobjekte"."XP_Plan_gid_seq"
MINVALUE 1;
GRANT ALL ON TABLE "XP_Basisobjekte"."XP_Plan_gid_seq" TO GROUP xp_user;
CREATE SEQUENCE "XP_Basisobjekte"."XP_Bereich_gid_seq"
MINVALUE 1;
GRANT ALL ON TABLE "XP_Basisobjekte"."XP_Bereich_gid_seq" TO GROUP xp_user;
CREATE SEQUENCE "XP_Basisobjekte"."XP_Objekt_gid_seq"
MINVALUE 1;
GRANT ALL ON TABLE "XP_Basisobjekte"."XP_Objekt_gid_seq" TO GROUP xp_user;
CREATE SEQUENCE "XP_Praesentationsobjekte"."XP_APObjekt_gid_seq"
MINVALUE 1;
GRANT ALL ON TABLE "XP_Praesentationsobjekte"."XP_APObjekt_gid_seq" TO GROUP xp_user;
CREATE SEQUENCE "XP_Praesentationsobjekte"."dientZurDarstellungVon_id_seq"
MINVALUE 1;
GRANT ALL ON TABLE "XP_Praesentationsobjekte"."dientZurDarstellungVon_id_seq" TO GROUP xp_user;
CREATE SEQUENCE "XP_Raster"."XP_Rasterdarstellung_id_seq"
MINVALUE 1;
GRANT ALL ON TABLE "XP_Raster"."XP_Rasterdarstellung_id_seq" TO GROUP xp_user;
CREATE SEQUENCE "XP_Basisobjekte"."XP_ExterneReferenz_id_seq"
MINVALUE 1;
GRANT ALL ON TABLE "XP_Basisobjekte"."XP_ExterneReferenz_id_seq" TO GROUP xp_user;
CREATE SEQUENCE "XP_Basisobjekte"."XP_TextAbschnitt_id_seq"
MINVALUE 1;
GRANT ALL ON TABLE "XP_Basisobjekte"."XP_TextAbschnitt_id_seq" TO GROUP xp_user;
CREATE SEQUENCE "XP_Basisobjekte"."XP_BegruendungAbschnitt_id_seq"
MINVALUE 1;
GRANT ALL ON TABLE "XP_Basisobjekte"."XP_BegruendungAbschnitt_id_seq" TO GROUP xp_user;
CREATE SEQUENCE "XP_Basisobjekte"."XP_VerfahrensMerkmal_id_seq"
MINVALUE 1;
GRANT ALL ON TABLE "XP_Basisobjekte"."XP_VerfahrensMerkmal_id_seq" TO GROUP xp_user;
CREATE SEQUENCE "XP_Sonstiges"."XP_Gemeinde_id_seq"
MINVALUE 1;
GRANT ALL ON TABLE "XP_Sonstiges"."XP_Gemeinde_id_seq" TO GROUP xp_user;
CREATE SEQUENCE "XP_Sonstiges"."XP_Plangeber_id_seq"
MINVALUE 1;
GRANT ALL ON TABLE "XP_Sonstiges"."XP_Plangeber_id_seq" TO GROUP xp_user;
CREATE SEQUENCE "XP_Sonstiges"."XP_Hoehenangabe_id_seq"
MINVALUE 1;
GRANT ALL ON TABLE "XP_Sonstiges"."XP_Hoehenangabe_id_seq" TO GROUP xp_user;
CREATE SEQUENCE "XP_Basisobjekte"."XP_SPEMassnahmenDaten_id_seq"
MINVALUE 1;
GRANT ALL ON TABLE "XP_Basisobjekte"."XP_SPEMassnahmenDaten_id_seq" TO GROUP xp_user;
CREATE SEQUENCE "XP_Basisobjekte"."XP_WirksamkeitBedingung_id_seq"
MINVALUE 1;
GRANT ALL ON TABLE "XP_Basisobjekte"."XP_WirksamkeitBedingung_id_seq" TO GROUP xp_user;
CREATE SEQUENCE "XP_Basisobjekte"."XP_Code_seq"
MINVALUE 1000000; -- eigene Codelistenwerte des Benutzers < 1000000
GRANT ALL ON TABLE "XP_Basisobjekte"."XP_Code_seq" TO GROUP xp_user;
-- *****************************************************
-- CREATE TRIGGER FUNCTIONs
-- *****************************************************
CREATE OR REPLACE FUNCTION "XP_Basisobjekte"."isAbstract"()
RETURNS trigger AS
$BODY$
BEGIN
IF (TG_OP = 'INSERT') THEN
RAISE EXCEPTION 'Einfügen in abstrakte Klasse ist nicht zulässig';
RETURN NULL;
END IF;
END; $BODY$
LANGUAGE 'plpgsql' VOLATILE
COST 100;
GRANT EXECUTE ON FUNCTION "XP_Basisobjekte"."isAbstract"() TO xp_user;
CREATE OR REPLACE FUNCTION "XP_Basisobjekte"."child_of_XP_ExterneReferenz"()
RETURNS trigger AS
$BODY$
DECLARE
num_parents integer;
BEGIN
If (TG_OP = 'INSERT') THEN
IF new.id IS NULL THEN
num_parents := 0;
new.id := nextval('"XP_Basisobjekte"."XP_ExterneReferenz_id_seq"');
ELSE
EXECUTE 'SELECT count(id) FROM "XP_Basisobjekte"."XP_ExterneReferenz"' ||
' WHERE id = ' || CAST(new.id as varchar) || ';' INTO num_parents;
IF pg_trigger_depth() = 1 THEN -- Trigger wird für unterste Kindtabelle aufgerufen
RAISE WARNING 'Die id sollte beim Einfügen in Tabelle % automatisch vergeben werden', TG_TABLE_NAME;
END IF;
END IF;
IF num_parents = 0 THEN
-- Elternobjekt anlegen
INSERT INTO "XP_Basisobjekte"."XP_ExterneReferenz"(id, "referenzName") VALUES(new.id, 'Externe Referenz ' || CAST(new.id as varchar));
END IF;
RETURN new;
ELSIf (TG_OP = 'UPDATE') THEN
new.id := old.id;
RETURN new;
ELSIF (TG_OP = 'DELETE') THEN
DELETE FROM "XP_Basisobjekte"."XP_ExterneReferenz" WHERE id = old.id;
RETURN old;
END IF;
END; $BODY$
LANGUAGE 'plpgsql' VOLATILE
COST 100;
GRANT EXECUTE ON FUNCTION "XP_Basisobjekte"."child_of_XP_ExterneReferenz"() TO xp_user;
CREATE OR REPLACE FUNCTION "XP_Basisobjekte"."change_to_XP_Plan"()
RETURNS trigger AS
$BODY$
BEGIN
IF (TG_OP = 'INSERT') THEN
INSERT INTO "XP_Basisobjekte"."XP_VerbundenerPlan"("verbundenerPlan", "planName", "nummer") VALUES(new.gid, new."name", new."nummer");
RETURN new;
ELSIF (TG_OP = 'UPDATE') THEN
new.gid := old.gid; --no change in gid allowed
UPDATE "XP_Basisobjekte"."XP_VerbundenerPlan" SET "planName" = new."name" WHERE "verbundenerPlan" = old.gid;
UPDATE "XP_Basisobjekte"."XP_VerbundenerPlan" SET "nummer" = new."nummer" WHERE "verbundenerPlan" = old.gid;
RETURN new;
ELSIF (TG_OP = 'DELETE') THEN
DELETE FROM "XP_Basisobjekte"."XP_VerbundenerPlan" WHERE "verbundenerPlan" = old.gid;
RETURN old;
END IF;
END; $BODY$
LANGUAGE 'plpgsql' VOLATILE
COST 100;
GRANT EXECUTE ON FUNCTION "XP_Basisobjekte"."change_to_XP_Plan"() TO xp_user;
CREATE OR REPLACE FUNCTION "XP_Basisobjekte"."change_to_XP_VerbundenerPlan"()
RETURNS trigger AS
$BODY$
BEGIN
IF (TG_OP = 'INSERT') THEN
new."planName" := COALESCE(new."planName",'kein Name in XP_VerbundenerPlan');
IF NEW."verbundenerPlan" IS NULL THEN
INSERT INTO "XP_Basisobjekte"."XP_Plan" ("name","nummer") VALUES(new."planName", new."nummer");
RETURN NULL;
ELSE
RETURN new;
END IF;
ELSIF (TG_OP = 'UPDATE') THEN
new."verbundenerPlan" := old."verbundenerPlan"; --no change in gid allowed
IF pg_trigger_depth() = 1 THEN
-- UPDATE-Statement wird nicht über den Trigger change_to_XP_Plan aufgerufen, sondern das UPDATE erfolgt direkt auf XP_VerbundenerPlan
new."planName" := old."planName";
new."nummer" := old."nummer";
END IF;
RETURN new;
END IF;
END; $BODY$
LANGUAGE 'plpgsql' VOLATILE
COST 100;
GRANT EXECUTE ON FUNCTION "XP_Basisobjekte"."change_to_XP_VerbundenerPlan"() TO xp_user;
CREATE OR REPLACE FUNCTION "XP_Basisobjekte"."child_of_XP_Plan"()
RETURNS trigger AS
$BODY$
DECLARE
num_parents integer;
BEGIN
IF (TG_OP = 'INSERT') THEN
IF new.gid IS NULL THEN
new.gid := nextval('"XP_Basisobjekte"."XP_Plan_gid_seq"');
num_parents := 0;
ELSE
EXECUTE 'SELECT count(gid) FROM "XP_Basisobjekte"."XP_Plan"' ||
' WHERE gid = ' || CAST(new.gid as varchar) || ';' INTO num_parents;
IF num_parents > 0 THEN
RAISE WARNING 'Einen XP_Plan mit dieser gid gibt es bereits, erzeuge neue gid';
new.gid := nextval('"XP_Basisobjekte"."XP_Plan_gid_seq"');
num_parents := 0;
ELSE
RAISE WARNING 'Die gid sollte beim Einfügen in Tabelle % automatisch vergeben werden', TG_TABLE_NAME;
END IF;
END IF;
IF new.name IS NULL THEN
new.name := 'XP_Plan ' || CAST(new.gid as varchar);
END IF;
IF num_parents = 0 THEN
INSERT INTO "XP_Basisobjekte"."XP_Plan"(gid, name) VALUES(new.gid, new.name);
END IF;
IF new."raeumlicherGeltungsbereich" IS NOT NULL THEN
new."raeumlicherGeltungsbereich" := ST_ForceRHR(new."raeumlicherGeltungsbereich");
END IF;
RETURN new;
ELSIF (TG_OP = 'UPDATE') THEN
new.gid := old.gid; --no change in gid allowed
IF new."raeumlicherGeltungsbereich" IS NOT NULL THEN
new."raeumlicherGeltungsbereich" := ST_ForceRHR(new."raeumlicherGeltungsbereich");
END IF;
RETURN new;
ELSIF (TG_OP = 'DELETE') THEN
DELETE FROM "XP_Basisobjekte"."XP_Plan" WHERE gid = old.gid;
RETURN old;
END IF;
END; $BODY$
LANGUAGE 'plpgsql' VOLATILE
COST 100;
GRANT EXECUTE ON FUNCTION "XP_Basisobjekte"."child_of_XP_Plan"() TO xp_user;
CREATE OR REPLACE FUNCTION "XP_Basisobjekte"."propagate_name_to_parent"()
RETURNS trigger AS
$BODY$
BEGIN
IF pg_trigger_depth() = 1 THEN -- UPDATE-Statement wird nicht über einen anderen Trigger aufgerufen
IF new.name != old.name THEN
IF TG_TABLE_NAME LIKE '%Plan' THEN
UPDATE "XP_Basisobjekte"."XP_Plan" SET name = new.name WHERE gid = old.gid;
ELSIF TG_TABLE_NAME LIKE '%Bereich' THEN
UPDATE "XP_Basisobjekte"."XP_Bereich" SET name = new.name WHERE gid = old.gid;
END IF;
END IF;
END IF;
RETURN new;
END; $BODY$
LANGUAGE 'plpgsql' VOLATILE
COST 100;
GRANT EXECUTE ON FUNCTION "XP_Basisobjekte"."propagate_name_to_parent"() TO xp_user;
CREATE OR REPLACE FUNCTION "XP_Basisobjekte"."propagate_name_to_child"()
RETURNS trigger AS
$BODY$
DECLARE
rec record;
BEGIN
IF pg_trigger_depth() = 1 THEN -- UPDATE-Statement wird nicht über einen anderen Trigger aufgerufen
IF new.name != old.name THEN
IF TG_TABLE_NAME = 'XP_Plan' THEN
FOR rec IN
SELECT nspname, relname
FROM pg_class c
JOIN pg_namespace n ON c.relnamespace = n.oid
WHERE relname IN ('FP_Plan', 'BP_Plan', 'LP_Plan', 'RP_Plan', 'SO_Plan')
LOOP
EXECUTE 'UPDATE ' || quote_ident(rec.nspname) || '.' || quote_ident(rec.relname) ||
'SET name = ' || quote_literal(new.name) || ' WHERE gid = ' || CAST(old.gid as varchar) || ';';
END LOOP;
ELSIF TG_TABLE_NAME = 'XP_Bereich' THEN
FOR rec IN
SELECT nspname, relname
FROM pg_class c
JOIN pg_namespace n ON c.relnamespace = n.oid
WHERE relname IN ('FP_Bereich', 'BP_Bereich', 'LP_Bereich', 'RP_Bereich', 'SO_Bereich')
LOOP
EXECUTE 'UPDATE ' || quote_ident(rec.nspname) || '.' || quote_ident(rec.relname) ||
'SET name = ' || quote_literal(new.name) || ' WHERE gid = ' || CAST(old.gid as varchar) || ';';
END LOOP;
END IF;
END IF;
END IF;
RETURN new;
END; $BODY$
LANGUAGE 'plpgsql' VOLATILE
COST 100;
GRANT EXECUTE ON FUNCTION "XP_Basisobjekte"."propagate_name_to_child"() TO xp_user;
CREATE OR REPLACE FUNCTION "XP_Basisobjekte"."child_of_XP_Bereich"()
RETURNS trigger AS
$BODY$
DECLARE
num_parents integer;
BEGIN
IF (TG_OP = 'INSERT') THEN
IF new.gid IS NULL THEN
new.gid := nextval('"XP_Basisobjekte"."XP_Bereich_gid_seq"');
num_parents := 0;
ELSE
EXECUTE 'SELECT count(gid) FROM "XP_Basisobjekte"."XP_Bereich"' ||
' WHERE gid = ' || CAST(new.gid as varchar) || ';' INTO num_parents;
IF num_parents > 0 THEN
RAISE WARNING 'Einen XP_Bereich mit dieser gid gibt es bereits, erzeuge neue gid';
new.gid := nextval('"XP_Basisobjekte"."XP_Bereich_gid_seq"');
num_parents := 0;
ELSE
RAISE WARNING 'Die gid sollte beim Einfügen in Tabelle % automatisch vergeben werden', TG_TABLE_NAME;
END IF;
END IF;
IF new.name IS NULL THEN
new.name := 'XP_Bereich ' || CAST(new.gid as varchar);
END IF;
IF num_parents = 0 THEN
INSERT INTO "XP_Basisobjekte"."XP_Bereich"(gid, name) VALUES(new.gid, new.name);
END IF;
IF new."geltungsbereich" IS NOT NULL THEN
new."geltungsbereich" := ST_ForceRHR(new."geltungsbereich");
END IF;
RETURN new;
ELSIF (TG_OP = 'UPDATE') THEN
new.gid := old.gid; --no change in id allowed
IF new."geltungsbereich" IS NOT NULL THEN
new."geltungsbereich" := ST_ForceRHR(new."geltungsbereich");
END IF;
IF new.name IS NULL THEN
new.name := old.name;
END IF;
RETURN new;
ELSIF (TG_OP = 'DELETE') THEN
DELETE FROM "XP_Basisobjekte"."XP_Bereich" WHERE gid = old.gid;
RETURN old;
END IF;
END; $BODY$
LANGUAGE 'plpgsql' VOLATILE
COST 100;
GRANT EXECUTE ON FUNCTION "XP_Basisobjekte"."child_of_XP_Bereich"() TO xp_user;
CREATE OR REPLACE FUNCTION "XP_Basisobjekte"."XP_Bereich_before_update"()
RETURNS trigger AS
$BODY$
BEGIN
IF new.name IS NULL THEN
new.name := old.name;
END IF;
return new;
END; $BODY$
LANGUAGE 'plpgsql' VOLATILE
COST 100;
GRANT EXECUTE ON FUNCTION "XP_Basisobjekte"."XP_Bereich_before_update"() TO xp_user;
CREATE OR REPLACE FUNCTION "XP_Basisobjekte"."change_to_XP_Objekt"()
RETURNS trigger AS
$BODY$
BEGIN
IF (TG_OP = 'INSERT') THEN
IF new.gid IS NULL THEN
new.gid := nextval('"XP_Basisobjekte"."XP_Objekt_gid_seq"');
END IF;
IF new.uuid IS NULL THEN
new.uuid := "XP_Basisobjekte"."create_uuid"();
END IF;
RETURN new;
ELSIF (TG_OP = 'UPDATE') THEN
new.gid := old.gid; --no change in gid allowed
IF new.uuid IS NULL THEN
new.uuid := old.uuid;
END IF;
RETURN new;
END IF;
END; $BODY$
LANGUAGE 'plpgsql' VOLATILE
COST 100;
GRANT EXECUTE ON FUNCTION "XP_Basisobjekte"."change_to_XP_Objekt"() TO xp_user;
CREATE OR REPLACE FUNCTION "XP_Basisobjekte"."create_gml_id"()
RETURNS trigger AS
$BODY$
BEGIN
IF new.gml_id IS NULL THEN
new.gml_id := "XP_Basisobjekte"."create_uuid"();
END IF;
RETURN new;
END; $BODY$
LANGUAGE 'plpgsql' VOLATILE
COST 100;
GRANT EXECUTE ON FUNCTION "XP_Basisobjekte"."create_gml_id"() TO xp_user;
-- FUNCTION: "XP_Basisobjekte"."child_of_XP_Objekt"()
-- DROP FUNCTION "XP_Basisobjekte"."child_of_XP_Objekt"();
CREATE OR REPLACE FUNCTION "XP_Basisobjekte"."child_of_XP_Objekt"()
RETURNS trigger
LANGUAGE 'plpgsql'
COST 100
VOLATILE NOT LEAKPROOF
AS $BODY$
DECLARE
parent_nspname varchar;
parent_relname varchar;
rec record;
num_parents integer;
BEGIN
parent_nspname := NULL;
-- die Elterntabelle rauskriegen und in Variablen speichern
For rec IN
SELECT
ns.nspname, c.relname
FROM pg_attribute att
JOIN (SELECT * FROM pg_constraint WHERE contype = 'f') fcon ON att.attrelid = fcon.conrelid AND att.attnum = ANY (fcon.conkey)
JOIN (SELECT * FROM pg_constraint WHERE contype = 'p') pcon ON att.attrelid = pcon.conrelid AND att.attnum = ANY (pcon.conkey)
JOIN pg_class c ON fcon.confrelid = c.oid
JOIN pg_namespace ns ON c.relnamespace = ns.oid
WHERE att.attnum > 0
AND att.attisdropped = false
AND att.attrelid = TG_RELID
AND array_length(pcon.conkey, 1) = 1
LOOP
parent_nspname := rec.nspname;
parent_relname := rec.relname;
END LOOP;
IF (TG_OP = 'INSERT') THEN
IF new.gid IS NULL THEN
num_parents := 0;
new.gid := nextval('"XP_Basisobjekte"."XP_Objekt_gid_seq"');
ELSE
EXECUTE 'SELECT count(gid) FROM ' || quote_ident(parent_nspname) || '.' || quote_ident(parent_relname) ||
' WHERE gid = ' || CAST(new.gid as varchar) || ';' INTO num_parents;
IF pg_trigger_depth() = 1 THEN -- Trigger wird für unterste Kindtabelle aufgerufen
RAISE WARNING 'Die gid sollte beim Einfügen in Tabelle % automatisch vergeben werden', TG_TABLE_NAME;
END IF;
END IF;
IF parent_nspname IS NOT NULL AND num_parents = 0 THEN
-- Elternobjekt anlegen
EXECUTE 'INSERT INTO ' || quote_ident(parent_nspname) || '.' || quote_ident(parent_relname) ||
'(gid) VALUES(' || CAST(new.gid as varchar) || ');';
END IF;
RETURN new;
ELSIF (TG_OP = 'UPDATE') THEN
new.gid := old.gid; --no change in gid allowed
RETURN new;
ELSIF (TG_OP = 'DELETE') THEN
IF parent_nspname IS NOT NULL THEN
-- Elternobjekt löschen
EXECUTE 'DELETE FROM ' || quote_ident(parent_nspname) || '.' || quote_ident(parent_relname) ||
' WHERE gid = ' || CAST(old.gid as varchar) || ';';
END IF;
RETURN old;
END IF;
END;
$BODY$;
GRANT EXECUTE ON FUNCTION "XP_Basisobjekte"."child_of_XP_Objekt"() TO xp_user;
CREATE OR REPLACE FUNCTION "XP_Praesentationsobjekte"."child_of_XP_APObjekt"()
RETURNS trigger AS
$BODY$
DECLARE
num_parents integer;
BEGIN
IF (TG_OP = 'INSERT') THEN
IF new.gid IS NULL THEN
num_parents := 0;
new.gid := nextval('"XP_Praesentationsobjekte"."XP_APObjekt_gid_seq"');
ELSE
EXECUTE 'SELECT count(gid) FROM "XP_Praesentationsobjekte"."XP_AbstraktesPraesentationsobjekt"' ||
' WHERE gid = ' || CAST(new.gid as varchar) || ';' INTO num_parents;
IF pg_trigger_depth() = 1 THEN -- Trigger wird für unterste Kindtabelle aufgerufen
RAISE WARNING 'Die gid sollte beim Einfügen in Tabelle % automatisch vergeben werden', TG_TABLE_NAME;
END IF;
END IF;
IF num_parents = 0 THEN
-- Elternobjekt anlegen
INSERT INTO "XP_Praesentationsobjekte"."XP_AbstraktesPraesentationsobjekt" (gid) VALUES (new.gid);
END IF;
RETURN new;
ELSIF (TG_OP = 'UPDATE') THEN
new.gid := old.gid; --no change in gid allowed
RETURN new;
ELSIF (TG_OP = 'DELETE') THEN
DELETE FROM "XP_Praesentationsobjekte"."XP_AbstraktesPraesentationsobjekt" WHERE gid = old.gid;
RETURN old;
END IF;
END; $BODY$
LANGUAGE 'plpgsql' VOLATILE
COST 100;
GRANT EXECUTE ON FUNCTION "XP_Praesentationsobjekte"."child_of_XP_APObjekt"() TO xp_user;
CREATE OR REPLACE FUNCTION "XP_Praesentationsobjekte"."child_of_XP_TPO"()
RETURNS trigger AS
$BODY$
DECLARE
num_parents integer;
BEGIN
IF (TG_OP = 'INSERT') THEN
IF new.gid IS NULL THEN
num_parents := 0;
new.gid := nextval('"XP_Praesentationsobjekte"."XP_APObjekt_gid_seq"');
ELSE
EXECUTE 'SELECT count(gid) FROM "XP_Praesentationsobjekte"."XP_TPO"' ||
' WHERE gid = ' || CAST(new.gid as varchar) || ';' INTO num_parents;
IF pg_trigger_depth() = 1 THEN -- Trigger wird für unterste Kindtabelle aufgerufen
RAISE WARNING 'Die gid sollte beim Einfügen in Tabelle % automatisch vergeben werden', TG_TABLE_NAME;
END IF;
END IF;
IF num_parents = 0 THEN
-- Elternobjekt anlegen
INSERT INTO "XP_Praesentationsobjekte"."XP_TPO" (gid) VALUES (new.gid);
END IF;
RETURN new;
ELSIF (TG_OP = 'UPDATE') THEN
new.gid := old.gid; --no change in gid allowed
RETURN new;
ELSIF (TG_OP = 'DELETE') THEN
DELETE FROM "XP_Praesentationsobjekte"."XP_TPO" WHERE gid = old.gid;
RETURN old;
END IF;
END; $BODY$
LANGUAGE 'plpgsql' VOLATILE
COST 100;
GRANT EXECUTE ON FUNCTION "XP_Praesentationsobjekte"."child_of_XP_TPO"() TO xp_user;
CREATE OR REPLACE FUNCTION "XP_Basisobjekte"."XP_Abschnitt_Konformitaet"()
RETURNS trigger AS
$BODY$
BEGIN
IF (TG_OP = 'INSERT') OR (TG_OP = 'UPDATE') THEN
IF new.text IS NULL AND new."refText" IS NULL THEN
new.text := 'kein Text';
RAISE WARNING 'Entweder text oder refText muss belegt sein!';
ELSIF new.text IS NOT NULL AND new."refText" IS NOT NULL THEN
new.text := NULL;
RAISE WARNING 'text und refText dürfen nicht gleichzeitig belegt sein!';
END IF;
RETURN new;
END IF;
END; $BODY$
LANGUAGE 'plpgsql' VOLATILE
COST 100;
GRANT EXECUTE ON FUNCTION "XP_Basisobjekte"."XP_Abschnitt_Konformitaet"() TO xp_user;
CREATE OR REPLACE FUNCTION "XP_Basisobjekte"."child_of_XP_TextAbschnitt"()
RETURNS trigger AS
$BODY$
DECLARE
num_parents integer;
BEGIN
IF (TG_OP = 'INSERT') THEN
IF new.id IS NULL THEN
num_parents := 0;
new.id := nextval('"XP_Basisobjekte"."XP_TextAbschnitt_id_seq"');
ELSE
EXECUTE 'SELECT count(id) FROM "XP_Basisobjekte"."XP_TextAbschnitt"' ||
' WHERE id = ' || CAST(new.id as varchar) || ';' INTO num_parents;
IF pg_trigger_depth() = 1 THEN -- Trigger wird für unterste Kindtabelle aufgerufen
RAISE WARNING 'Die id sollte beim Einfügen in Tabelle % automatisch vergeben werden', TG_TABLE_NAME;
END IF;
END IF;
IF num_parents = 0 THEN
-- Elternobjekt anlegen
INSERT INTO "XP_Basisobjekte"."XP_TextAbschnitt" (id) VALUES (new.id);
END IF;
RETURN new;
ELSIF (TG_OP = 'UPDATE') THEN
new.id := old.id; --no change in id allowed
RETURN new;
ELSIF (TG_OP = 'DELETE') THEN
DELETE FROM "XP_Basisobjekte"."XP_TextAbschnitt" WHERE id = old.id;
RETURN old;
END IF;
END; $BODY$
LANGUAGE 'plpgsql' VOLATILE
COST 100;
GRANT EXECUTE ON FUNCTION "XP_Basisobjekte"."child_of_XP_TextAbschnitt"() TO xp_user;
CREATE OR REPLACE FUNCTION "XP_Basisobjekte"."isFlaechenschlussobjekt"()
RETURNS trigger AS
$BODY$
DECLARE
ebene integer;
BEGIN
IF (TG_OP = 'DELETE') THEN
RETURN old;
ELSE
IF new."position" IS NOT NULL THEN
new."position" := ST_ForceRHR(new."position");
END IF;
-- Neu 5.1: Flächenschluss wird nur zwischen Objekten der ebene = 0 hergestellt
EXECUTE 'SELECT ebene FROM "XP_Basisobjekte"."XP_Objekt"' ||
' WHERE gid = ' || CAST(new.gid as varchar) || ';' INTO ebene;
IF ebene = 0 THEN
new.flaechenschluss := true;
END IF;
RETURN new;
END IF;
END; $BODY$
LANGUAGE 'plpgsql' VOLATILE
COST 100;
GRANT EXECUTE ON FUNCTION "XP_Basisobjekte"."isFlaechenschlussobjekt"() TO xp_user;
CREATE OR REPLACE FUNCTION "XP_Basisobjekte"."isFlaechenobjekt"()
RETURNS trigger AS
$BODY$
BEGIN
IF (TG_OP = 'INSERT' or TG_OP = 'UPDATE') THEN
IF new."position" IS NOT NULL THEN
new."position" := ST_ForceRHR(new."position");
END IF;
END IF;
IF (TG_OP = 'INSERT') THEN
IF new."flaechenschluss" IS NULL THEN
new."flaechenschluss" := false;
END IF;
END IF;
RETURN new;
END; $BODY$
LANGUAGE 'plpgsql' VOLATILE
COST 100;
GRANT EXECUTE ON FUNCTION "XP_Basisobjekte"."isFlaechenobjekt"() TO xp_user;
CREATE OR REPLACE FUNCTION "XP_Basisobjekte"."isUeberlagerungsobjekt"()
RETURNS trigger AS
$BODY$
BEGIN
IF (TG_OP = 'DELETE') THEN
RETURN old;
ELSE
IF new."position" IS NOT NULL THEN
new."position" := ST_ForceRHR(new."position");
END IF;
new.flaechenschluss := false;
RETURN new;
END IF;
END; $BODY$
LANGUAGE 'plpgsql' VOLATILE
COST 100;
GRANT EXECUTE ON FUNCTION "XP_Basisobjekte"."isUeberlagerungsobjekt"() TO xp_user;
CREATE OR REPLACE FUNCTION "XP_Basisobjekte"."positionFollowsRHR"()
RETURNS trigger AS
$BODY$
BEGIN
IF new."position" IS NOT NULL THEN
new."position" := ST_ForceRHR(new."position");
END IF;
RETURN new;
END; $BODY$
LANGUAGE 'plpgsql' VOLATILE
COST 100;
GRANT EXECUTE ON FUNCTION "XP_Basisobjekte"."positionFollowsRHR"() TO xp_user;
CREATE OR REPLACE FUNCTION "XP_Basisobjekte"."isCodeList"()
RETURNS trigger AS
$BODY$
BEGIN
IF (TG_OP = 'INSERT') THEN
IF NEW."Code" IS NULL THEN
NEW."Code" := nextval('"XP_Basisobjekte"."XP_Code_seq"');
ELSE
IF NEW."Code" > 1000000 THEN
NEW."Code" := nextval('"XP_Basisobjekte"."XP_Code_seq"');
END IF;
END IF;
RETURN new;
ELSIF (TG_OP = 'UPDATE') THEN
new."Code" := old."Code";
RETURN new;
END IF;
END; $BODY$
LANGUAGE 'plpgsql' VOLATILE
COST 100;
GRANT EXECUTE ON FUNCTION "XP_Basisobjekte"."isCodeList"() TO xp_user;
-- *****************************************************
-- CREATE TABLEs
-- *****************************************************
-- -----------------------------------------------------
-- Table "XP_Modellbereich"
-- -----------------------------------------------------
CREATE TABLE public."XP_Modellbereich" (
"Kurz" VARCHAR(2) NOT NULL ,
"Modellbereich" VARCHAR(64) NOT NULL ,
PRIMARY KEY ("Kurz") );
COMMENT ON TABLE public."XP_Modellbereich" IS 'Auflistung der in dieser Datenbank enthaltenen Modellbereiche';
GRANT SELECT ON TABLE public."XP_Modellbereich" TO xp_gast;
-- -----------------------------------------------------
-- Table "XP_Enumerationen"."XP_Rechtsstand"
-- -----------------------------------------------------
CREATE TABLE "XP_Enumerationen"."XP_Rechtsstand" (
"Code" INTEGER NOT NULL ,
"Bezeichner" VARCHAR(64) NOT NULL ,
PRIMARY KEY ("Code") );
GRANT SELECT ON TABLE "XP_Enumerationen"."XP_Rechtsstand" TO xp_gast;
-- -----------------------------------------------------
-- Table "XP_Enumerationen"."XP_AllgArtDerBaulNutzung"
-- -----------------------------------------------------
CREATE TABLE "XP_Enumerationen"."XP_AllgArtDerBaulNutzung" (
"Code" INTEGER NOT NULL ,
"Bezeichner" VARCHAR(64) NOT NULL ,
PRIMARY KEY ("Code") );
GRANT SELECT ON TABLE "XP_Enumerationen"."XP_AllgArtDerBaulNutzung" TO xp_gast;
-- -----------------------------------------------------
-- Table "XP_Enumerationen"."XP_BesondereArtDerBaulNutzung"
-- -----------------------------------------------------
CREATE TABLE "XP_Enumerationen"."XP_BesondereArtDerBaulNutzung" (
"Code" INTEGER NOT NULL ,
"Bezeichner" VARCHAR(64) NOT NULL ,
PRIMARY KEY ("Code") );
GRANT SELECT ON TABLE "XP_Enumerationen"."XP_BesondereArtDerBaulNutzung" TO xp_gast;
-- -----------------------------------------------------
-- Table "XP_Enumerationen"."XP_Sondernutzungen"
-- -----------------------------------------------------
CREATE TABLE "XP_Enumerationen"."XP_Sondernutzungen" (
"Code" INTEGER NOT NULL ,
"Bezeichner" VARCHAR(64) NOT NULL ,
PRIMARY KEY ("Code") );
GRANT SELECT ON TABLE "XP_Enumerationen"."XP_Sondernutzungen" TO xp_gast;
-- -----------------------------------------------------
-- Table "XP_Enumerationen"."XP_AbweichungBauNVOTypen"
-- -----------------------------------------------------
CREATE TABLE "XP_Enumerationen"."XP_AbweichungBauNVOTypen" (
"Code" INTEGER NOT NULL ,
"Bezeichner" VARCHAR(64) NOT NULL ,
PRIMARY KEY ("Code") );
GRANT SELECT ON TABLE "XP_Enumerationen"."XP_AbweichungBauNVOTypen" TO xp_gast;
-- -----------------------------------------------------
-- Table "XP_Enumerationen"."XP_ZweckbestimmungGemeinbedarf"
-- -----------------------------------------------------
CREATE TABLE "XP_Enumerationen"."XP_ZweckbestimmungGemeinbedarf" (
"Code" INTEGER NOT NULL ,
"Bezeichner" VARCHAR(64) NOT NULL ,
PRIMARY KEY ("Code") );
GRANT SELECT ON TABLE "XP_Enumerationen"."XP_ZweckbestimmungGemeinbedarf" TO xp_gast;
-- -----------------------------------------------------
-- Table "XP_Enumerationen"."XP_KlassifizSchutzgebietNaturschutzrecht"
-- -----------------------------------------------------
CREATE TABLE "XP_Enumerationen"."XP_KlassifizSchutzgebietNaturschutzrecht" (
"Code" INTEGER NOT NULL,
"Bezeichner" VARCHAR(64) NOT NULL,
PRIMARY KEY ("Code"));
GRANT SELECT ON TABLE "XP_Enumerationen"."XP_KlassifizSchutzgebietNaturschutzrecht" TO xp_gast;
-- -----------------------------------------------------
-- Table "XP_Enumerationen"."XP_ZweckbestimmungSpielSportanlage"
-- -----------------------------------------------------
CREATE TABLE "XP_Enumerationen"."XP_ZweckbestimmungSpielSportanlage" (
"Code" INTEGER NOT NULL ,
"Bezeichner" VARCHAR(64) NOT NULL ,
PRIMARY KEY ("Code") );
GRANT SELECT ON TABLE "XP_Enumerationen"."XP_ZweckbestimmungSpielSportanlage" TO xp_gast;
-- -----------------------------------------------------
-- Table "XP_Enumerationen"."XP_ZweckbestimmungGruen"
-- -----------------------------------------------------
CREATE TABLE "XP_Enumerationen"."XP_ZweckbestimmungGruen" (
"Code" INTEGER NOT NULL ,
"Bezeichner" VARCHAR(64) NOT NULL ,
PRIMARY KEY ("Code") );
GRANT SELECT ON TABLE "XP_Enumerationen"."XP_ZweckbestimmungGruen" TO xp_gast;
-- -----------------------------------------------------
-- Table "XP_Enumerationen"."XP_ZweckbestimmungWald"
-- -----------------------------------------------------
CREATE TABLE "XP_Enumerationen"."XP_ZweckbestimmungWald" (
"Code" INTEGER NOT NULL ,
"Bezeichner" VARCHAR(64) NOT NULL ,
PRIMARY KEY ("Code") );
GRANT SELECT ON TABLE "XP_Enumerationen"."XP_ZweckbestimmungWald" TO xp_gast;
-- -----------------------------------------------------
-- Table "XP_Enumerationen"."XP_EigentumsartWald"
-- -----------------------------------------------------
CREATE TABLE "XP_Enumerationen"."XP_EigentumsartWald" (
"Code" INTEGER NOT NULL ,
"Bezeichner" VARCHAR(64) NOT NULL ,
PRIMARY KEY ("Code") );
GRANT SELECT ON TABLE "XP_Enumerationen"."XP_EigentumsartWald" TO xp_gast;
-- -----------------------------------------------------
-- Table "XP_Enumerationen"."XP_WaldbetretungTyp"
-- -----------------------------------------------------
CREATE TABLE "XP_Enumerationen"."XP_WaldbetretungTyp" (
"Code" INTEGER NOT NULL ,
"Bezeichner" VARCHAR(64) NOT NULL ,
PRIMARY KEY ("Code") );
GRANT SELECT ON TABLE "XP_Enumerationen"."XP_WaldbetretungTyp" TO xp_gast;
-- -----------------------------------------------------
-- Table "XP_Enumerationen"."XP_ZweckbestimmungLandwirtschaft"
-- -----------------------------------------------------
CREATE TABLE "XP_Enumerationen"."XP_ZweckbestimmungLandwirtschaft" (
"Code" INTEGER NOT NULL ,
"Bezeichner" VARCHAR(64) NOT NULL ,
PRIMARY KEY ("Code") );
GRANT SELECT ON TABLE "XP_Enumerationen"."XP_ZweckbestimmungLandwirtschaft" TO xp_gast;
-- -----------------------------------------------------
-- Table "XP_Enumerationen"."XP_Nutzungsform"
-- -----------------------------------------------------
CREATE TABLE "XP_Enumerationen"."XP_Nutzungsform" (
"Code" INTEGER NOT NULL ,
"Bezeichner" VARCHAR(64) NOT NULL ,
PRIMARY KEY ("Code") );
GRANT SELECT ON TABLE "XP_Enumerationen"."XP_Nutzungsform" TO xp_gast;
-- -----------------------------------------------------
-- Table "XP_Enumerationen"."XP_ZweckbestimmungKennzeichnung"
-- -----------------------------------------------------
CREATE TABLE "XP_Enumerationen"."XP_ZweckbestimmungKennzeichnung" (
"Code" INTEGER NOT NULL ,
"Bezeichner" VARCHAR(64) NOT NULL ,
PRIMARY KEY ("Code") );
GRANT SELECT ON TABLE "XP_Enumerationen"."XP_ZweckbestimmungKennzeichnung" TO xp_gast;
-- -----------------------------------------------------
-- Table "XP_Enumerationen"."XP_ZweckbestimmungVerEntsorgung"
-- -----------------------------------------------------
CREATE TABLE "XP_Enumerationen"."XP_ZweckbestimmungVerEntsorgung" (
"Code" INTEGER NOT NULL ,
"Bezeichner" VARCHAR(64) NOT NULL ,
PRIMARY KEY ("Code") );
GRANT SELECT ON TABLE "XP_Enumerationen"."XP_ZweckbestimmungVerEntsorgung" TO xp_gast;
-- -----------------------------------------------------
-- Table "XP_Enumerationen"."XP_ZweckbestimmungGewaesser"
-- -----------------------------------------------------
CREATE TABLE "XP_Enumerationen"."XP_ZweckbestimmungGewaesser" (
"Code" INTEGER NOT NULL ,
"Bezeichner" VARCHAR(64) NOT NULL ,
PRIMARY KEY ("Code") );
GRANT SELECT ON TABLE "XP_Enumerationen"."XP_ZweckbestimmungGewaesser" TO xp_gast;
-- -----------------------------------------------------
-- Table "XP_Enumerationen"."XP_ZweckbestimmungWasserwirtschaft"
-- -----------------------------------------------------
CREATE TABLE "XP_Enumerationen"."XP_ZweckbestimmungWasserwirtschaft" (
"Code" INTEGER NOT NULL ,