⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 triggers.out

📁 关系型数据库 Postgresql 6.5.2
💻 OUT
📖 第 1 页 / 共 2 页
字号:
' language 'plpgsql';QUERY: create trigger tg_hslot_bu before update    on HSlot for each row execute procedure tg_hslot_bu();QUERY: create function tg_phone_bu() returns opaque as 'begin    if new.slotname != old.slotname then        delete from PHone where slotname = old.slotname;	insert into PHone (		    slotname,		    comment,		    slotlink		) values (		    new.slotname,		    new.comment,		    new.slotlink		);        return null;    end if;    return new;end;' language 'plpgsql';QUERY: create trigger tg_phone_bu before update    on PHone for each row execute procedure tg_phone_bu();QUERY: create function tg_backlink_a() returns opaque as 'declare    dummy	integer;begin    if tg_op = ''INSERT'' then        if new.backlink != '''' then	    dummy := tg_backlink_set(new.backlink, new.slotname);	end if;	return new;    end if;    if tg_op = ''UPDATE'' then        if new.backlink != old.backlink then	    if old.backlink != '''' then	        dummy := tg_backlink_unset(old.backlink, old.slotname);	    end if;	    if new.backlink != '''' then	        dummy := tg_backlink_set(new.backlink, new.slotname);	    end if;	else	    if new.slotname != old.slotname and new.backlink != '''' then	        dummy := tg_slotlink_set(new.backlink, new.slotname);	    end if;	end if;	return new;    end if;    if tg_op = ''DELETE'' then        if old.backlink != '''' then	    dummy := tg_backlink_unset(old.backlink, old.slotname);	end if;	return old;    end if;end;' language 'plpgsql';QUERY: create trigger tg_backlink_a after insert or update or delete    on PSlot for each row execute procedure tg_backlink_a('PS');QUERY: create trigger tg_backlink_a after insert or update or delete    on WSlot for each row execute procedure tg_backlink_a('WS');QUERY: create trigger tg_backlink_a after insert or update or delete    on PLine for each row execute procedure tg_backlink_a('PL');QUERY: create function tg_backlink_set(bpchar, bpchar)returns integer as 'declare    myname	alias for $1;    blname	alias for $2;    mytype	char(2);    link	char(4);    rec		record;begin    mytype := substr(myname, 1, 2);    link := mytype || substr(blname, 1, 2);    if link = ''PLPL'' then        raise exception		''backlink between two phone lines does not make sense'';    end if;    if link in (''PLWS'', ''WSPL'') then        raise exception		''direct link of phone line to wall slot not permitted'';    end if;    if mytype = ''PS'' then        select into rec * from PSlot where slotname = myname;	if not found then	    raise exception ''% does not exists'', myname;	end if;	if rec.backlink != blname then	    update PSlot set backlink = blname where slotname = myname;	end if;	return 0;    end if;    if mytype = ''WS'' then        select into rec * from WSlot where slotname = myname;	if not found then	    raise exception ''% does not exists'', myname;	end if;	if rec.backlink != blname then	    update WSlot set backlink = blname where slotname = myname;	end if;	return 0;    end if;    if mytype = ''PL'' then        select into rec * from PLine where slotname = myname;	if not found then	    raise exception ''% does not exists'', myname;	end if;	if rec.backlink != blname then	    update PLine set backlink = blname where slotname = myname;	end if;	return 0;    end if;    raise exception ''illegal backlink beginning with %'', mytype;end;' language 'plpgsql';QUERY: create function tg_backlink_unset(bpchar, bpchar)returns integer as 'declare    myname	alias for $1;    blname	alias for $2;    mytype	char(2);    rec		record;begin    mytype := substr(myname, 1, 2);    if mytype = ''PS'' then        select into rec * from PSlot where slotname = myname;	if not found then	    return 0;	end if;	if rec.backlink = blname then	    update PSlot set backlink = '''' where slotname = myname;	end if;	return 0;    end if;    if mytype = ''WS'' then        select into rec * from WSlot where slotname = myname;	if not found then	    return 0;	end if;	if rec.backlink = blname then	    update WSlot set backlink = '''' where slotname = myname;	end if;	return 0;    end if;    if mytype = ''PL'' then        select into rec * from PLine where slotname = myname;	if not found then	    return 0;	end if;	if rec.backlink = blname then	    update PLine set backlink = '''' where slotname = myname;	end if;	return 0;    end if;end;' language 'plpgsql';QUERY: create function tg_slotlink_a() returns opaque as 'declare    dummy	integer;begin    if tg_op = ''INSERT'' then        if new.slotlink != '''' then	    dummy := tg_slotlink_set(new.slotlink, new.slotname);	end if;	return new;    end if;    if tg_op = ''UPDATE'' then        if new.slotlink != old.slotlink then	    if old.slotlink != '''' then	        dummy := tg_slotlink_unset(old.slotlink, old.slotname);	    end if;	    if new.slotlink != '''' then	        dummy := tg_slotlink_set(new.slotlink, new.slotname);	    end if;	else	    if new.slotname != old.slotname and new.slotlink != '''' then	        dummy := tg_slotlink_set(new.slotlink, new.slotname);	    end if;	end if;	return new;    end if;    if tg_op = ''DELETE'' then        if old.slotlink != '''' then	    dummy := tg_slotlink_unset(old.slotlink, old.slotname);	end if;	return old;    end if;end;' language 'plpgsql';QUERY: create trigger tg_slotlink_a after insert or update or delete    on PSlot for each row execute procedure tg_slotlink_a('PS');QUERY: create trigger tg_slotlink_a after insert or update or delete    on WSlot for each row execute procedure tg_slotlink_a('WS');QUERY: create trigger tg_slotlink_a after insert or update or delete    on IFace for each row execute procedure tg_slotlink_a('IF');QUERY: create trigger tg_slotlink_a after insert or update or delete    on HSlot for each row execute procedure tg_slotlink_a('HS');QUERY: create trigger tg_slotlink_a after insert or update or delete    on PHone for each row execute procedure tg_slotlink_a('PH');QUERY: create function tg_slotlink_set(bpchar, bpchar)returns integer as 'declare    myname	alias for $1;    blname	alias for $2;    mytype	char(2);    link	char(4);    rec		record;begin    mytype := substr(myname, 1, 2);    link := mytype || substr(blname, 1, 2);    if link = ''PHPH'' then        raise exception		''slotlink between two phones does not make sense'';    end if;    if link in (''PHHS'', ''HSPH'') then        raise exception		''link of phone to hub does not make sense'';    end if;    if link in (''PHIF'', ''IFPH'') then        raise exception		''link of phone to hub does not make sense'';    end if;    if link in (''PSWS'', ''WSPS'') then        raise exception		''slotlink from patchslot to wallslot not permitted'';    end if;    if mytype = ''PS'' then        select into rec * from PSlot where slotname = myname;	if not found then	    raise exception ''% does not exists'', myname;	end if;	if rec.slotlink != blname then	    update PSlot set slotlink = blname where slotname = myname;	end if;	return 0;    end if;    if mytype = ''WS'' then        select into rec * from WSlot where slotname = myname;	if not found then	    raise exception ''% does not exists'', myname;	end if;	if rec.slotlink != blname then	    update WSlot set slotlink = blname where slotname = myname;	end if;	return 0;    end if;    if mytype = ''IF'' then        select into rec * from IFace where slotname = myname;	if not found then	    raise exception ''% does not exists'', myname;	end if;	if rec.slotlink != blname then	    update IFace set slotlink = blname where slotname = myname;	end if;	return 0;    end if;    if mytype = ''HS'' then        select into rec * from HSlot where slotname = myname;	if not found then	    raise exception ''% does not exists'', myname;	end if;	if rec.slotlink != blname then	    update HSlot set slotlink = blname where slotname = myname;	end if;	return 0;    end if;    if mytype = ''PH'' then        select into rec * from PHone where slotname = myname;	if not found then	    raise exception ''% does not exists'', myname;	end if;	if rec.slotlink != blname then	    update PHone set slotlink = blname where slotname = myname;	end if;	return 0;    end if;    raise exception ''illegal slotlink beginning with %'', mytype;end;' language 'plpgsql';QUERY: create function tg_slotlink_unset(bpchar, bpchar)returns integer as 'declare    myname	alias for $1;    blname	alias for $2;    mytype	char(2);    rec		record;begin    mytype := substr(myname, 1, 2);    if mytype = ''PS'' then        select into rec * from PSlot where slotname = myname;	if not found then	    return 0;	end if;	if rec.slotlink = blname then	    update PSlot set slotlink = '''' where slotname = myname;	end if;	return 0;    end if;    if mytype = ''WS'' then        select into rec * from WSlot where slotname = myname;	if not found then	    return 0;	end if;	if rec.slotlink = blname then	    update WSlot set slotlink = '''' where slotname = myname;	end if;	return 0;    end if;    if mytype = ''IF'' then        select into rec * from IFace where slotname = myname;	if not found then	    return 0;	end if;	if rec.slotlink = blname then	    update IFace set slotlink = '''' where slotname = myname;	end if;	return 0;    end if;    if mytype = ''HS'' then        select into rec * from HSlot where slotname = myname;	if not found then	    return 0;	end if;	if rec.slotlink = blname then	    update HSlot set slotlink = '''' where slotname = myname;	end if;	return 0;    end if;    if mytype = ''PH'' then        select into rec * from PHone where slotname = myname;	if not found then	    return 0;	end if;	if rec.slotlink = blname then	    update PHone set slotlink = '''' where slotname = myname;	end if;	return 0;    end if;end;' language 'plpgsql';

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -