/[BackupPC]/trunk/sql/09_backup_parts_trigger.sql
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/sql/09_backup_parts_trigger.sql

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 369 by dpavlin, Tue Jan 31 22:04:47 2006 UTC revision 370 by iklaric, Mon May 7 07:33:49 2007 UTC
# Line 32  create trigger do_backup_parts_check Line 32  create trigger do_backup_parts_check
32  create or replace function backup_backup_parts_check() returns trigger as '  create or replace function backup_backup_parts_check() returns trigger as '
33  declare  declare
34          b_id            integer;          b_id            integer;
35            old_b_id        integer;
36          my_part_nr      integer;          my_part_nr      integer;
37          calc_part       integer;          calc_part       integer;
38  begin  begin
39          if (TG_OP = ''INSERT'') then          if (TG_OP = ''INSERT'') then
40                  -- raise notice ''trigger: % backup_id %'', TG_OP, new.backup_id;                  raise notice ''trigger: % backup_id %'', TG_OP, new.backup_id;
41                  b_id = new.backup_id;                  b_id = new.backup_id;
42                  my_part_nr = new.part_nr;                  my_part_nr = new.part_nr;
43                  execute ''update backups set parts = parts + 1 where id = '' || b_id;                  execute ''update backups set parts = parts + 1 where id = '' || b_id;
44          elsif (TG_OP = ''DELETE'') then          elsif (TG_OP = ''DELETE'') then
45                  -- raise notice ''trigger: % backup_id %'', TG_OP, old.backup_id;                  raise notice ''trigger: % backup_id %, old.part_nr %'', TG_OP, old.backup_id, old.part_nr;
46                  b_id = old.backup_id;                  b_id = old.backup_id;
47                  my_part_nr = old.part_nr;                  my_part_nr = old.part_nr - 1;
48                  execute ''update backups set parts = parts - 1 where id = '' || b_id;                  execute ''update backups set parts = parts - 1 where id = '' || b_id;
49          end if;          end if;
50          calc_part := (select count(part_nr) from backup_parts where backup_id = b_id);          calc_part := (select count(part_nr) from backup_parts where backup_id = b_id);
51          if ( my_part_nr != calc_part ) then          if ( my_part_nr != calc_part ) then
52                  raise exception ''Update of backup_parts with backup_id % aborted, requested part_nr is % and calulated next is %'', b_id, my_part_nr, calc_part;          raise exception ''Update of backup_parts with backup_id % aborted, requested part_nr is % and calulated next is %'', b_id, my_part_nr, calc_part;
53            
54          end if;          end if;
55          return null;          return null;
56  end;  end;

Legend:
Removed from v.369  
changed lines
  Added in v.370

  ViewVC Help
Powered by ViewVC 1.1.26