/[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

Contents of /trunk/sql/09_backup_parts_trigger.sql

Parent Directory Parent Directory | Revision Log Revision Log


Revision 324 - (show annotations)
Tue Jan 31 16:22:21 2006 UTC (18 years, 4 months ago) by dpavlin
File size: 865 byte(s)
 r9162@llin:  dpavlin | 2006-01-31 17:21:33 +0100
 added trigger to ensure integrity of backup_parts

1 alter table backups alter column parts set default 0;
2
3 create or replace function backup_parts_check() returns trigger as '
4 declare
5 b_parts integer;
6 b_counted integer;
7 b_id integer;
8 begin
9 if (TG_OP=''UPDATE'') then
10 b_id := old.id;
11 b_parts := old.parts;
12 elsif (TG_OP = ''INSERT'') then
13 b_id := new.id;
14 b_parts := new.parts;
15 end if;
16 b_counted := (select count(*) from backup_parts where backup_id = b_id);
17 -- raise notice ''backup % parts %'', b_id, b_parts;
18 if ( b_parts != b_counted ) then
19 raise exception ''Update of backup % aborted, requested % parts and there are really % parts'', b_id, b_parts, b_counted;
20 end if;
21 return null;
22 end;
23 ' language plpgsql;
24
25 drop trigger do_backup_parts_check on backups;
26
27 create trigger do_backup_parts_check
28 after insert or update or delete on backups
29 for each row execute procedure backup_parts_check();
30

  ViewVC Help
Powered by ViewVC 1.1.26