insert into atualizacoes(atu_nome) values ('v20030001_070420.sql'); alter table examerequisicao add exr_resultadoempdf boolean; alter table examerequisicaoresultado add ert_resultadopdf text; insert into atualizacoes(atu_nome) values ('v20030002_070420.sql'); alter table receberpagar alter rpg_ipivalor type numeric(15, 4); alter table receberpagar alter rpg_icmsvalor type numeric(15, 4); insert into atualizacoes(atu_nome) values ('v20030003_130420.sql'); alter table notafiscal alter nfi_ipivalor type numeric(15, 4); alter table notafiscal alter nfi_icmsvalor type numeric(15, 4); insert into atualizacoes(atu_nome) values ('v20030004_220420.sql'); alter table requisicaoimagens add rmi_tipo varchar(1) default 'O'; insert into atualizacoes(atu_nome) values ('v20030005_280420.sql'); set session_replication_role=replica; alter table faturaexamerequisicao alter fer_total type numeric(15,5); alter table faturaexamerequisicao alter fer_totalch type numeric(15,5); insert into atualizacoes(atu_nome) values ('v20030006_120520.sql'); set session_replication_role=replica; alter table paciente alter pac_email type varchar(150); drop function fn_td_tabelaprecoexames() cascade; create function fn_td_tabelaprecoexames() returns opaque as ' declare numrows integer; begin delete from tabelaprecoexamesusuario where tabelaprecoexamesusuario.fil_codigo = old.fil_codigo and tabelaprecoexamesusuario.tpe_codigo = old.tpe_codigo; select count(*) into numrows from detalhetabelaprecometodologia where detalhetabelaprecometodologia.fil_codigo = old.fil_codigo and detalhetabelaprecometodologia.tpe_codigo = old.tpe_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela detalhetabelaprecometodologia.''; end if; delete from tabelaprecoexamesporte where tabelaprecoexamesporte.fil_codigo = old.fil_codigo and tabelaprecoexamesporte.tpe_codigo = old.tpe_codigo; select count(*) into numrows from convenios where convenios.fil_codigo = old.fil_codigo and convenios.tpe_codigo = old.tpe_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela convenios.''; end if; delete from detalhetabelapreco where detalhetabelapreco.fil_codigo = old.fil_codigo and detalhetabelapreco.tpe_codigo = old.tpe_codigo; return old; end;' language 'plpgsql'; create trigger td_tabelaprecoexames after delete on tabelaprecoexames for each row execute procedure fn_td_tabelaprecoexames(); drop function fn_ti_tabelaprecoexames() cascade; create function fn_ti_tabelaprecoexames() returns opaque as ' declare numrows integer; tmp varchar; begin select count(*) into numrows from filiais_postocoleta where new.fil_codigo = filiais_postocoleta.fil_codigo; tmp:=''filiais_postocoleta|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela filiais_postocoleta. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; return new; end;' language 'plpgsql'; create trigger ti_tabelaprecoexames after insert on tabelaprecoexames for each row execute procedure fn_ti_tabelaprecoexames(); drop function fn_tu_tabelaprecoexames() cascade; create function fn_tu_tabelaprecoexames() returns opaque as ' declare numrows integer; tmp varchar; begin if (old.fil_codigo <> new.fil_codigo or old.tpe_codigo <> new.tpe_codigo) then select count(*) from tabelaprecoexamesusuario where tabelaprecoexamesusuario.fil_codigo = old.fil_codigo and tabelaprecoexamesusuario.tpe_codigo = old.tpe_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela tabelaprecoexamesusuario.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.tpe_codigo <> new.tpe_codigo) then select count(*) from detalhetabelaprecometodologia where detalhetabelaprecometodologia.fil_codigo = old.fil_codigo and detalhetabelaprecometodologia.tpe_codigo = old.tpe_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela detalhetabelaprecometodologia.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.tpe_codigo <> new.tpe_codigo) then select count(*) from tabelaprecoexamesporte where tabelaprecoexamesporte.fil_codigo = old.fil_codigo and tabelaprecoexamesporte.tpe_codigo = old.tpe_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela tabelaprecoexamesporte.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.tpe_codigo <> new.tpe_codigo) then select count(*) from convenios where convenios.fil_codigo = old.fil_codigo and convenios.tpe_codigo = old.tpe_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela convenios.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.tpe_codigo <> new.tpe_codigo) then select count(*) from detalhetabelapreco where detalhetabelapreco.fil_codigo = old.fil_codigo and detalhetabelapreco.tpe_codigo = old.tpe_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela detalhetabelapreco.''; end if; end if; select count(*) into numrows from filiais_postocoleta where new.fil_codigo = filiais_postocoleta.fil_codigo; tmp:=''filiais_postocoleta|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela filiais_postocoleta. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; return old; end;' language 'plpgsql'; create trigger tu_tabelaprecoexames after update on tabelaprecoexames for each row execute procedure fn_tu_tabelaprecoexames(); drop function fn_ti_tabelaprecoexamesusuario() cascade; create function fn_ti_tabelaprecoexamesusuario() returns opaque as ' declare numrows integer; tmp varchar; begin select count(*) into numrows from usuario where new.usr_codigo = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from tabelaprecoexames where new.fil_codigo = tabelaprecoexames.fil_codigo and new.tpe_codigo = tabelaprecoexames.tpe_codigo; tmp:=''tabelaprecoexames|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''tpe_codigo='' || new.tpe_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.tpe_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela tabelaprecoexames. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; return new; end;' language 'plpgsql'; create trigger ti_tabelaprecoexamesusuario after insert on tabelaprecoexamesusuario for each row execute procedure fn_ti_tabelaprecoexamesusuario(); drop function fn_tu_tabelaprecoexamesusuario() cascade; create function fn_tu_tabelaprecoexamesusuario() returns opaque as ' declare numrows integer; tmp varchar; begin select count(*) into numrows from usuario where new.usr_codigo = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from tabelaprecoexames where new.fil_codigo = tabelaprecoexames.fil_codigo and new.tpe_codigo = tabelaprecoexames.tpe_codigo; tmp:=''tabelaprecoexames|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''tpe_codigo='' || new.tpe_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.tpe_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela tabelaprecoexames. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; return old; end;' language 'plpgsql'; create trigger tu_tabelaprecoexamesusuario after update on tabelaprecoexamesusuario for each row execute procedure fn_tu_tabelaprecoexamesusuario(); insert into atualizacoes(atu_nome) values ('v20030007_130520.sql');