Debian Codegraph @

tests/inputs/bubs_tak_ard.prc

raw
1 CREATE OR REPLACE TRIGGER bubs_tak_ard
2 /* ***************************************************************************
3 *
4 * Trigger: bubs_tak_ard
5 *
6 * After row delete trigger to maintain history for the table bubs_taken.
7 *
8 * Generated by Invantive Producer.
9 *
10 * (C) Copyright 2004-2017 Invantive Software BV, the Netherlands. All rights reserved.
11 *
12 * ***************************************************************************/
13 after delete
14 on bubs_taken
15 for each row
16 declare
17 l_effective date;
18 l_anti_date boolean;
19 l_dummy pls_integer;
20 begin
21 if true /* History is enabled. */
22 then
23 l_effective := itgen_history.get_effective_date('bubs_taken', 'D', l_anti_date);
24 if l_anti_date
25 then
26 --
27 -- Check that there are no more recent mutations.
28 --
29 begin
30 select 1
31 into l_dummy
32 from bubshtaken
33 where h_datum_start > l_effective
34 and id =:old.id
35 ;
36 bubs_error_handler.handle_error
37 ( '{res:bubs_anti_date_not_possible_before_later_history'
38 || '?bubshtaken'
39 || '&' || to_char(:old.id)
40 || '}'
41 , p_are_code => 'takitg025'
42 , p_top_error => null
43 );
44 exception
45 when no_data_found
46 then
47 null;
48 when too_many_rows
49 then
50 bubs_error_handler.handle_error
51 ( '{res:bubs_anti_date_not_possible_before_later_history'
52 || '?bubshtaken'
53 || '&' || to_char(:old.id)
54 || '}'
55 , p_are_code => 'takitg026'
56 , p_top_error => null
57 );
58 end;
59 end if;
60 --
61 update bubshtaken
62 set h_datum_einde = l_effective-1/86400
63 , h_actief_als_gevuld = null
64 where /* Allow use of index. */ case when h_actief_als_gevuld is not null then id else null end = :old.id
65 and h_datum_einde = to_date('99991231', 'YYYYMMDD')
66 and h_actief_als_gevuld = 'J' /* For performance. */
67 ;
68 if sql%rowcount <> 1
69 then
70 bubs_error_handler.handle_error
71 ( '{res:bubs_could_not_finish_history'
72 || '?bubshtaken'
73 || '&' || to_char(:old.id)
74 || '&' || sql%rowcount
75 || '}'
76 , p_are_code => 'takitg027'
77 , p_top_error => null
78 );
79 end if;
80 end if;
81 end;
82 /