-
Notifications
You must be signed in to change notification settings - Fork 1
/
procura.sql
1640 lines (1231 loc) · 38.6 KB
/
procura.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
--
-- PostgreSQL database dump
--
-- Started on 2011-02-01 11:41:14 CET
SET statement_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = off;
SET check_function_bodies = false;
SET client_min_messages = warning;
SET escape_string_warning = off;
--
-- TOC entry 363 (class 2612 OID 18641)
-- Name: plpgsql; Type: PROCEDURAL LANGUAGE; Schema: -; Owner: procura
--
CREATE PROCEDURAL LANGUAGE plpgsql;
ALTER PROCEDURAL LANGUAGE plpgsql OWNER TO procura;
SET search_path = public, pg_catalog;
--
-- TOC entry 19 (class 1255 OID 18642)
-- Dependencies: 6 363
-- Name: archiviazione(); Type: FUNCTION; Schema: public; Owner: procura
--
CREATE FUNCTION archiviazione() RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
IF OLD.datafine IS NULL AND NEW.datafine IS NOT NULL THEN
INSERT INTO varprocesso
SELECT pro.id, pro.datainizio, pro.datafine, ind.id, ind.datainizio, ind.datafine
FROM processo pro, indagine ind
WHERE pro.id=NEW.id AND pro.indagine=ind.id;
INSERT INTO varprova
SELECT id, indagine
FROM prova
WHERE indagine=NEW.indagine;
INSERT INTO varcondannato
SELECT con.imputato, con.processo, ind.genere, ind.datanascita
FROM condanna con, indagato ind
WHERE con.processo=NEW.id AND con.imputato=ind.id;
INSERT INTO varprosciolto
SELECT pro.imputato, pro.processo, ind.genere, ind.datanascita
FROM proscioglimento pro, indagato ind
WHERE pro.processo=NEW.id AND pro.imputato=ind.id;
INSERT INTO varorganizzazionecriminale
SELECT organizzazionecriminale, imputato, inizio, fine
FROM appartenenza
WHERE imputato IN (SELECT imputato FROM carico WHERE processo=NEW.id);
END IF;
RETURN NEW;
END;
$$;
ALTER FUNCTION public.archiviazione() OWNER TO procura;
--
-- TOC entry 20 (class 1255 OID 18643)
-- Dependencies: 6 363
-- Name: carico(); Type: FUNCTION; Schema: public; Owner: procura
--
CREATE FUNCTION carico() RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
PERFORM *
FROM carico
WHERE imputato=OLD.indagato
AND processo IN (SELECT id FROM processo WHERE indagine=OLD.indagine);
IF FOUND THEN
RAISE EXCEPTION 'Non è possibile modificare una citazione di indagine dopo che il processo correlato è già iniziato'
USING ERRCODE = '61000';
END IF;
RETURN NEW;
END;
$$;
ALTER FUNCTION public.carico() OWNER TO procura;
--
-- TOC entry 21 (class 1255 OID 18644)
-- Dependencies: 363 6
-- Name: citazione(); Type: FUNCTION; Schema: public; Owner: procura
--
CREATE FUNCTION citazione() RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
PERFORM *
FROM citazione
WHERE indagato=NEW.imputato
AND indagine IN (SELECT indagine FROM processo WHERE id=NEW.processo);
IF NOT FOUND THEN
RAISE EXCEPTION 'Non è possibile iniziare un processo contro un soggetto che non è stato indagato'
USING ERRCODE = '60000';
END IF;
RETURN NEW;
END;
$$;
ALTER FUNCTION public.citazione() OWNER TO procura;
--
-- TOC entry 22 (class 1255 OID 18645)
-- Dependencies: 363 6
-- Name: conclusioneprocesso(); Type: FUNCTION; Schema: public; Owner: procura
--
CREATE FUNCTION conclusioneprocesso() RETURNS trigger
LANGUAGE plpgsql
AS $$
DECLARE
carichi INTEGER;
condanne INTEGER;
proscioglimenti INTEGER;
BEGIN
SELECT count(*) INTO carichi
FROM carico
WHERE processo=NEW.processo
AND imputato=NEW.imputato;
SELECT count(*) INTO condanne
FROM condanna
WHERE processo=NEW.processo
AND imputato=NEW.imputato;
SELECT count(*) INTO proscioglimenti
FROM proscioglimento
WHERE processo=NEW.processo
AND imputato=NEW.imputato;
IF (carichi-(condanne+proscioglimenti))=0 THEN
UPDATE processo
SET concluso=true
WHERE id=NEW.processo;
END IF;
RETURN NEW;
END;
$$;
ALTER FUNCTION public.conclusioneprocesso() OWNER TO procura;
--
-- TOC entry 23 (class 1255 OID 18646)
-- Dependencies: 363 6
-- Name: condanna(); Type: FUNCTION; Schema: public; Owner: procura
--
CREATE FUNCTION condanna() RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
PERFORM *
FROM carico
WHERE processo=NEW.processo AND imputato=NEW.imputato;
IF NOT FOUND THEN
RAISE EXCEPTION 'Non è possibile inserire un esito per un processo che non è mai stato a carico di questo imputato'
USING ERRCODE = '40000';
ELSE
PERFORM *
FROM condanna
WHERE processo=NEW.processo AND imputato=NEW.imputato;
IF FOUND THEN
RAISE EXCEPTION 'Non è possibile inserire un proscioglimento per un processo per il quale è già stata emanata una condanna'
USING ERRCODE = '41000';
END IF;
END IF;
RETURN NEW;
END;
$$;
ALTER FUNCTION public.condanna() OWNER TO procura;
--
-- TOC entry 24 (class 1255 OID 18647)
-- Dependencies: 363 6
-- Name: datafine(); Type: FUNCTION; Schema: public; Owner: procura
--
CREATE FUNCTION datafine() RETURNS trigger
LANGUAGE plpgsql
AS $$
DECLARE
conc BOOLEAN;
BEGIN
IF NEW.datafine IS NOT NULL THEN
SELECT concluso INTO conc
FROM processo
WHERE id=NEW.id;
IF NOT conc THEN
RAISE EXCEPTION 'Non è possibile specificare la data di chiusura di un processo se ci sono ancora degli esiti non registrati'
USING ERRCODE = '30000';
END IF;
END IF;
RETURN NEW;
END;
$$;
ALTER FUNCTION public.datafine() OWNER TO procura;
--
-- TOC entry 25 (class 1255 OID 18648)
-- Dependencies: 363 6
-- Name: dataindagine(); Type: FUNCTION; Schema: public; Owner: procura
--
CREATE FUNCTION dataindagine() RETURNS trigger
LANGUAGE plpgsql
AS $$
DECLARE
dataFineIndagine DATE;
BEGIN
SELECT datafine INTO dataFineIndagine
FROM indagine
WHERE id=NEW.indagine;
IF dataFineIndagine IS NULL THEN
RAISE EXCEPTION 'L''indagine preliminare non è terminata, impossibile associarvi un processo'
USING ERRCODE = '10000';
ELSE
IF dataFineIndagine > NEW.datainizio THEN
RAISE EXCEPTION 'La data di inizio processo non può precedere la data di terminazione dell''indagine'
USING ERRCODE = '11000';
END IF;
END IF;
RETURN NEW;
END;
$$;
ALTER FUNCTION public.dataindagine() OWNER TO procura;
--
-- TOC entry 26 (class 1255 OID 18649)
-- Dependencies: 6 363
-- Name: dataprocesso(); Type: FUNCTION; Schema: public; Owner: procura
--
CREATE FUNCTION dataprocesso() RETURNS trigger
LANGUAGE plpgsql
AS $$
DECLARE
dataInizioProcesso DATE;
BEGIN
SELECT datainizio INTO dataInizioProcesso
FROM processo
WHERE indagine=NEW.id;
IF dataInizioProcesso IS NOT NULL THEN
IF NEW.datafine IS NULL THEN
RAISE EXCEPTION 'L''indagine preliminare è stata chiusa per l''inizio del processo, non è possibile riaprirla'
USING ERRCODE = '12000';
ELSE
IF dataInizioProcesso < NEW.datafine THEN
RAISE EXCEPTION 'L''indagine preliminare è stata associata ad un processo iniziato il %, non è possibile fissare la chiusura delle indagini dopo tale data', dataInizioProcesso
USING ERRCODE = '13000';
END IF;
END IF;
END IF;
RETURN NEW;
END;
$$;
ALTER FUNCTION public.dataprocesso() OWNER TO procura;
--
-- TOC entry 27 (class 1255 OID 18650)
-- Dependencies: 6 363
-- Name: illecito(); Type: FUNCTION; Schema: public; Owner: procura
--
CREATE FUNCTION illecito() RETURNS trigger
LANGUAGE plpgsql
AS $$
DECLARE
ill TEXT;
BEGIN
SELECT illecito INTO ill
FROM citazione
WHERE indagato=NEW.imputato
AND indagine IN (SELECT indagine FROM processo WHERE id=NEW.processo);
IF NEW.capoimputazione IS NULL THEN
NEW.capoimputazione := ill;
ELSE
IF NEW.capoimputazione NOT LIKE ill THEN
RAISE EXCEPTION 'Il capo di imputazione di un processo deve essere uguale all''illecito da verificare durante l''indagine'
USING ERRCODE = '20000';
END IF;
END IF;
RETURN NEW;
END;
$$;
ALTER FUNCTION public.illecito() OWNER TO procura;
--
-- TOC entry 31 (class 1255 OID 19091)
-- Dependencies: 6 363
-- Name: nuovaindagine(date); Type: FUNCTION; Schema: public; Owner: procura
--
CREATE FUNCTION nuovaindagine(inizio date) RETURNS integer
LANGUAGE plpgsql
AS $$
DECLARE
newid integer;
BEGIN
SELECT nextval('indagine_sq') INTO newid;
INSERT INTO indagine VALUES (newid, inizio);
RETURN newid;
END;
$$;
ALTER FUNCTION public.nuovaindagine(inizio date) OWNER TO procura;
--
-- TOC entry 32 (class 1255 OID 19092)
-- Dependencies: 6 363
-- Name: nuovoprocesso(integer, text, date); Type: FUNCTION; Schema: public; Owner: procura
--
CREATE FUNCTION nuovoprocesso(indagine integer, gradogiudizio text, datainizio date) RETURNS integer
LANGUAGE plpgsql
AS $$
DECLARE
newid integer;
BEGIN
SELECT nextval('processo_sq') INTO newid;
INSERT INTO processo VALUES (newid, indagine, gradogiudizio, datainizio);
RETURN newid;
END;
$$;
ALTER FUNCTION public.nuovoprocesso(indagine integer, gradogiudizio text, datainizio date) OWNER TO procura;
--
-- TOC entry 33 (class 1255 OID 18651)
-- Dependencies: 363 6
-- Name: processo(); Type: FUNCTION; Schema: public; Owner: procura
--
CREATE FUNCTION processo() RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
PERFORM *
FROM processo
WHERE indagine=OLD.indagine;
IF FOUND THEN
PERFORM *
FROM prova
WHERE indagine=OLD.indagine;
IF NOT FOUND THEN
RAISE EXCEPTION 'Non è possibile lasciare un processo senza neanche una prova prodotta dall''indagine preliminare'
USING ERRCODE = '51000';
END IF;
END IF;
RETURN NEW;
END;
$$;
ALTER FUNCTION public.processo() OWNER TO procura;
--
-- TOC entry 28 (class 1255 OID 18652)
-- Dependencies: 6 363
-- Name: proscioglimento(); Type: FUNCTION; Schema: public; Owner: procura
--
CREATE FUNCTION proscioglimento() RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
PERFORM *
FROM carico
WHERE processo=NEW.processo AND imputato=NEW.imputato;
IF NOT FOUND THEN
RAISE EXCEPTION 'Non è possibile inserire un esito per un processo che non è mai stato a carico di questo imputato'
USING ERRCODE = '40000';
ELSE
PERFORM *
FROM proscioglimento
WHERE processo=NEW.processo AND imputato=NEW.imputato;
IF FOUND THEN
RAISE EXCEPTION 'Non è possibile inserire una condanna per un processo per il quale è già stata emanato un proscioglimento'
USING ERRCODE = '42000';
END IF;
END IF;
RETURN NEW;
END;
$$;
ALTER FUNCTION public.proscioglimento() OWNER TO procura;
--
-- TOC entry 29 (class 1255 OID 18653)
-- Dependencies: 363 6
-- Name: prove(); Type: FUNCTION; Schema: public; Owner: procura
--
CREATE FUNCTION prove() RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
PERFORM *
FROM prova
WHERE indagine=NEW.indagine;
IF NOT FOUND THEN
RAISE EXCEPTION 'Non è possibile aprire un processo se l''indagine preliminare non ha prodotto alcuna prova'
USING ERRCODE = '50000';
END IF;
RETURN NEW;
END;
$$;
ALTER FUNCTION public.prove() OWNER TO procura;
--
-- TOC entry 30 (class 1255 OID 18654)
-- Dependencies: 363 6
-- Name: valoriiniziali(); Type: FUNCTION; Schema: public; Owner: procura
--
CREATE FUNCTION valoriiniziali() RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
NEW.concluso := FALSE;
NEW.datafine := NULL;
RETURN NEW;
END;
$$;
ALTER FUNCTION public.valoriiniziali() OWNER TO procura;
SET default_tablespace = '';
SET default_with_oids = false;
--
-- TOC entry 1550 (class 1259 OID 18655)
-- Dependencies: 1849 6
-- Name: appartenenza; Type: TABLE; Schema: public; Owner: procura; Tablespace:
--
CREATE TABLE appartenenza (
imputato integer NOT NULL,
organizzazionecriminale character varying(50) NOT NULL,
inizio date NOT NULL,
fine date,
CONSTRAINT date_ck CHECK ((inizio < fine))
);
ALTER TABLE public.appartenenza OWNER TO procura;
--
-- TOC entry 1551 (class 1259 OID 18659)
-- Dependencies: 6
-- Name: carico; Type: TABLE; Schema: public; Owner: procura; Tablespace:
--
CREATE TABLE carico (
processo integer NOT NULL,
imputato integer NOT NULL,
capoimputazione text
);
ALTER TABLE public.carico OWNER TO procura;
--
-- TOC entry 1552 (class 1259 OID 18665)
-- Dependencies: 6
-- Name: citazione; Type: TABLE; Schema: public; Owner: procura; Tablespace:
--
CREATE TABLE citazione (
indagato integer NOT NULL,
indagine integer NOT NULL,
illecito text NOT NULL
);
ALTER TABLE public.citazione OWNER TO procura;
--
-- TOC entry 1553 (class 1259 OID 18671)
-- Dependencies: 6
-- Name: condanna; Type: TABLE; Schema: public; Owner: procura; Tablespace:
--
CREATE TABLE condanna (
processo integer NOT NULL,
imputato integer NOT NULL,
entita text NOT NULL
);
ALTER TABLE public.condanna OWNER TO procura;
--
-- TOC entry 1554 (class 1259 OID 18677)
-- Dependencies: 6
-- Name: copertura; Type: TABLE; Schema: public; Owner: procura; Tablespace:
--
CREATE TABLE copertura (
indagato integer NOT NULL,
incaricopa character varying(50) NOT NULL
);
ALTER TABLE public.copertura OWNER TO procura;
--
-- TOC entry 1555 (class 1259 OID 18680)
-- Dependencies: 6
-- Name: imputato; Type: TABLE; Schema: public; Owner: procura; Tablespace:
--
CREATE TABLE imputato (
indagato integer NOT NULL
);
ALTER TABLE public.imputato OWNER TO procura;
--
-- TOC entry 1556 (class 1259 OID 18683)
-- Dependencies: 6
-- Name: incaricopa; Type: TABLE; Schema: public; Owner: procura; Tablespace:
--
CREATE TABLE incaricopa (
nome character varying(50) NOT NULL
);
ALTER TABLE public.incaricopa OWNER TO procura;
--
-- TOC entry 1557 (class 1259 OID 18686)
-- Dependencies: 6
-- Name: indagato_sq; Type: SEQUENCE; Schema: public; Owner: procura
--
CREATE SEQUENCE indagato_sq
START WITH 1
INCREMENT BY 1
NO MAXVALUE
NO MINVALUE
CACHE 1;
ALTER TABLE public.indagato_sq OWNER TO procura;
--
-- TOC entry 1955 (class 0 OID 0)
-- Dependencies: 1557
-- Name: indagato_sq; Type: SEQUENCE SET; Schema: public; Owner: procura
--
SELECT pg_catalog.setval('indagato_sq', 4, true);
--
-- TOC entry 1558 (class 1259 OID 18688)
-- Dependencies: 1850 1851 6
-- Name: indagato; Type: TABLE; Schema: public; Owner: procura; Tablespace:
--
CREATE TABLE indagato (
id integer DEFAULT nextval('indagato_sq'::regclass) NOT NULL,
nome character varying(30) NOT NULL,
cognome character varying(30) NOT NULL,
datanascita date NOT NULL,
luogonascita character varying(50),
residenza text NOT NULL,
genere "char" NOT NULL,
CONSTRAINT genere_ck CHECK (((genere = 'm'::"char") OR (genere = 'f'::"char")))
);
ALTER TABLE public.indagato OWNER TO procura;
--
-- TOC entry 1559 (class 1259 OID 18696)
-- Dependencies: 6
-- Name: indagine_sq; Type: SEQUENCE; Schema: public; Owner: procura
--
CREATE SEQUENCE indagine_sq
START WITH 1
INCREMENT BY 1
NO MAXVALUE
NO MINVALUE
CACHE 1;
ALTER TABLE public.indagine_sq OWNER TO procura;
--
-- TOC entry 1956 (class 0 OID 0)
-- Dependencies: 1559
-- Name: indagine_sq; Type: SEQUENCE SET; Schema: public; Owner: procura
--
SELECT pg_catalog.setval('indagine_sq', 4, true);
--
-- TOC entry 1560 (class 1259 OID 18698)
-- Dependencies: 1852 1853 6
-- Name: indagine; Type: TABLE; Schema: public; Owner: procura; Tablespace:
--
CREATE TABLE indagine (
id integer DEFAULT nextval('indagine_sq'::regclass) NOT NULL,
datainizio date NOT NULL,
datafine date,
CONSTRAINT date_ck CHECK ((datainizio < datafine))
);
ALTER TABLE public.indagine OWNER TO procura;
--
-- TOC entry 1561 (class 1259 OID 18703)
-- Dependencies: 6
-- Name: organizzazionecriminale; Type: TABLE; Schema: public; Owner: procura; Tablespace:
--
CREATE TABLE organizzazionecriminale (
nome character varying(50) NOT NULL
);
ALTER TABLE public.organizzazionecriminale OWNER TO procura;
--
-- TOC entry 1562 (class 1259 OID 18706)
-- Dependencies: 6
-- Name: processo_sq; Type: SEQUENCE; Schema: public; Owner: procura
--
CREATE SEQUENCE processo_sq
START WITH 1
INCREMENT BY 1
NO MAXVALUE
NO MINVALUE
CACHE 1;
ALTER TABLE public.processo_sq OWNER TO procura;
--
-- TOC entry 1957 (class 0 OID 0)
-- Dependencies: 1562
-- Name: processo_sq; Type: SEQUENCE SET; Schema: public; Owner: procura
--
SELECT pg_catalog.setval('processo_sq', 6, true);
--
-- TOC entry 1563 (class 1259 OID 18708)
-- Dependencies: 1854 1855 1856 1857 6
-- Name: processo; Type: TABLE; Schema: public; Owner: procura; Tablespace:
--
CREATE TABLE processo (
id integer DEFAULT nextval('processo_sq'::regclass) NOT NULL,
indagine integer NOT NULL,
gradogiudizio character varying(11) NOT NULL,
datainizio date NOT NULL,
concluso boolean DEFAULT false NOT NULL,
datafine date,
CONSTRAINT date_ck CHECK ((datainizio < datafine)),
CONSTRAINT gradogiudizio_ck CHECK (((((gradogiudizio)::text = 'Primo grado'::text) OR ((gradogiudizio)::text = 'Appello'::text)) OR ((gradogiudizio)::text = 'Cassazione'::text)))
);
ALTER TABLE public.processo OWNER TO procura;
--
-- TOC entry 1564 (class 1259 OID 18715)
-- Dependencies: 6
-- Name: proscioglimento; Type: TABLE; Schema: public; Owner: procura; Tablespace:
--
CREATE TABLE proscioglimento (
processo integer NOT NULL,
imputato integer NOT NULL,
motivo text NOT NULL
);
ALTER TABLE public.proscioglimento OWNER TO procura;
--
-- TOC entry 1565 (class 1259 OID 18721)
-- Dependencies: 6
-- Name: prova_sq; Type: SEQUENCE; Schema: public; Owner: procura
--
CREATE SEQUENCE prova_sq
START WITH 1
INCREMENT BY 1
NO MAXVALUE
NO MINVALUE
CACHE 1;
ALTER TABLE public.prova_sq OWNER TO procura;
--
-- TOC entry 1958 (class 0 OID 0)
-- Dependencies: 1565
-- Name: prova_sq; Type: SEQUENCE SET; Schema: public; Owner: procura
--
SELECT pg_catalog.setval('prova_sq', 4, true);
--
-- TOC entry 1566 (class 1259 OID 18723)
-- Dependencies: 1858 1859 1860 6
-- Name: prova; Type: TABLE; Schema: public; Owner: procura; Tablespace:
--
CREATE TABLE prova (
id integer DEFAULT nextval('prova_sq'::regclass) NOT NULL,
indagine integer NOT NULL,
descrizione text NOT NULL,
tipo character varying(9) NOT NULL,
identificativo integer,
file bytea,
formato character varying(9),
CONSTRAINT formato_ck CHECK ((((((formato)::text = 'documento'::text) OR ((formato)::text = 'immagine'::text)) OR ((formato)::text = 'audio'::text)) OR ((formato)::text = 'video'::text))),
CONSTRAINT tipo_ck CHECK ((((tipo)::text = 'materiale'::text) OR ((tipo)::text = 'digitale'::text)))
);
ALTER TABLE public.prova OWNER TO procura;
--
-- TOC entry 1567 (class 1259 OID 18732)
-- Dependencies: 6
-- Name: varcondannato; Type: TABLE; Schema: public; Owner: procura; Tablespace:
--
CREATE TABLE varcondannato (
idimputato integer NOT NULL,
idprocesso integer NOT NULL,
genere "char" NOT NULL,
datanascita date NOT NULL
);
ALTER TABLE public.varcondannato OWNER TO procura;
--
-- TOC entry 1568 (class 1259 OID 18735)
-- Dependencies: 6
-- Name: varorganizzazionecriminale; Type: TABLE; Schema: public; Owner: procura; Tablespace:
--
CREATE TABLE varorganizzazionecriminale (
nome character varying(50) NOT NULL,
idimputato integer NOT NULL,
inizioappartenenza date NOT NULL,
fineappartenenza date
);
ALTER TABLE public.varorganizzazionecriminale OWNER TO procura;
--
-- TOC entry 1569 (class 1259 OID 18738)
-- Dependencies: 6
-- Name: varprocesso; Type: TABLE; Schema: public; Owner: procura; Tablespace:
--
CREATE TABLE varprocesso (
idprocesso integer NOT NULL,
inizioprocesso date NOT NULL,
fineprocesso date NOT NULL,
idindagine integer NOT NULL,
inizioindagine date NOT NULL,
fineindagine date NOT NULL
);
ALTER TABLE public.varprocesso OWNER TO procura;
--
-- TOC entry 1570 (class 1259 OID 18741)
-- Dependencies: 6
-- Name: varprosciolto; Type: TABLE; Schema: public; Owner: procura; Tablespace:
--
CREATE TABLE varprosciolto (
idimputato integer NOT NULL,
idprocesso integer NOT NULL,
genere "char" NOT NULL,
datanascita date NOT NULL
);
ALTER TABLE public.varprosciolto OWNER TO procura;
--
-- TOC entry 1571 (class 1259 OID 18744)
-- Dependencies: 6
-- Name: varprova; Type: TABLE; Schema: public; Owner: procura; Tablespace:
--
CREATE TABLE varprova (
idprova integer NOT NULL,
idindagine integer NOT NULL
);
ALTER TABLE public.varprova OWNER TO procura;
--
-- TOC entry 1932 (class 0 OID 18655)
-- Dependencies: 1550
-- Data for Name: appartenenza; Type: TABLE DATA; Schema: public; Owner: procura
--
COPY appartenenza (imputato, organizzazionecriminale, inizio, fine) FROM stdin;
2 Banda Bassotti 2010-09-21 \N
\.
--
-- TOC entry 1933 (class 0 OID 18659)
-- Dependencies: 1551
-- Data for Name: carico; Type: TABLE DATA; Schema: public; Owner: procura
--
COPY carico (processo, imputato, capoimputazione) FROM stdin;
1 1 Furto con scasso al fortino di Paperon de' Paperoni
2 1 Rapimento di Minnie
1 2 Furto con scasso al fortino di Paperon de' Paperoni
3 2 Frode fiscale
\.
--
-- TOC entry 1934 (class 0 OID 18665)
-- Dependencies: 1552
-- Data for Name: citazione; Type: TABLE DATA; Schema: public; Owner: procura
--
COPY citazione (indagato, indagine, illecito) FROM stdin;
1 1 Furto con scasso al fortino di Paperon de' Paperoni
2 1 Furto con scasso al fortino di Paperon de' Paperoni
1 2 Rapimento di Minnie
2 3 Frode fiscale
4 4 Traffico di stupefacenti
1 4 Spaccio di droga
2 4 Spaccio di droga
\.
--
-- TOC entry 1935 (class 0 OID 18671)
-- Dependencies: 1553
-- Data for Name: condanna; Type: TABLE DATA; Schema: public; Owner: procura
--
COPY condanna (processo, imputato, entita) FROM stdin;
1 2 12 anni di carcere
\.
--
-- TOC entry 1936 (class 0 OID 18677)
-- Dependencies: 1554
-- Data for Name: copertura; Type: TABLE DATA; Schema: public; Owner: procura
--
COPY copertura (indagato, incaricopa) FROM stdin;
1 Sindaco di Topolinia
1 Comandante della Polizia di Paperopoli
2 Sindaco di Topolinia
\.
--
-- TOC entry 1937 (class 0 OID 18680)
-- Dependencies: 1555
-- Data for Name: imputato; Type: TABLE DATA; Schema: public; Owner: procura
--
COPY imputato (indagato) FROM stdin;
1
2
\.
--
-- TOC entry 1938 (class 0 OID 18683)
-- Dependencies: 1556
-- Data for Name: incaricopa; Type: TABLE DATA; Schema: public; Owner: procura
--
COPY incaricopa (nome) FROM stdin;
Sindaco di Topolinia
Comandante della Polizia di Paperopoli
Sindaco di Paperopoli
\.
--
-- TOC entry 1939 (class 0 OID 18688)
-- Dependencies: 1558
-- Data for Name: indagato; Type: TABLE DATA; Schema: public; Owner: procura
--
COPY indagato (id, nome, cognome, datanascita, luogonascita, residenza, genere) FROM stdin;
1 Macchia Nera 1985-01-01 Topolinia via Paperopoli 7, 12345 Topolinia TP m
2 Pietro Gambadilegno 1079-01-01 Topolinia via Paperopoli 30, 12345 Topolinia TP m
\.
--
-- TOC entry 1940 (class 0 OID 18698)
-- Dependencies: 1560
-- Data for Name: indagine; Type: TABLE DATA; Schema: public; Owner: procura
--
COPY indagine (id, datainizio, datafine) FROM stdin;
1 2010-01-15 2010-07-30
2 2010-06-30 2010-09-21
3 2010-07-20 2010-10-31
\.
--
-- TOC entry 1941 (class 0 OID 18703)
-- Dependencies: 1561
-- Data for Name: organizzazionecriminale; Type: TABLE DATA; Schema: public; Owner: procura
--
COPY organizzazionecriminale (nome) FROM stdin;
Banda Bassotti
\.
--
-- TOC entry 1942 (class 0 OID 18708)