I have the following table:
create table TB_CON /* contracts */
(
id_dpt numeric(18) not null, /* department ID */
id_con numeric(18) not null, /* row ID */
contract varchar(13) not null,
description varchar(40) not null,
valid_fm date, /* validity start */
valid_to date, /* validity end */
work_hours integer
primary key (id_con)
) ;
Database is Firebird 1.5
I need After Insert and a After Update triggers that will prevent a user from inserting 2 equal codes in overlapping validity periods.
you may find the following SP useful:
ALTER PROCEDURE OVERLAP (
A1 INTEGER,
B1 INTEGER,
A2 INTEGER,
B2 INTEGER )
RETURNS (
RESULT INTEGER )
AS
declare variable a integer;
declare variable b integer;
begin
result=0;
if ( a1 is null ) then
begin
suspend;
exit;
end
if ( b1 is null ) then
begin
suspend;
exit;
end
if ( a2 is null ) then
begin
suspend;
exit;
end
if ( b2 is null ) then
begin
suspend;
exit;
end
if ( b1<=a2 ) then
begin
suspend;
exit;
end
if ( a1>=b2 ) then
begin
suspend;
exit;
end
if ( ( a2<=a1 ) and (b2>=b1) ) then
begin
result=b1-a1;
suspend;
exit;
end
if ( (a2>=a1) and (b1<=b2) ) then
begin
result= b1-a2;
suspend;
exit;
end
if ( (a1>=a2) and (b1>=b2) ) then
begin
result=b2 - a1;
suspend;
exit;
end
if ( (a1>=a2) and (b1<=b2) ) then
begin
result=b1 - a1;
suspend;
exit;
end
if ( (a2>=a1) and (b2<=b1) ) then
begin
result=b2 - a2;
suspend;
exit;
end
end^
The triggers should take into due account the following special cases:
valid_fm null means 'no validity start' 'valid from the start of time'
valid_to null means 'no validity end' 'valid to the end of time'
## Deliverables
1) Complete and fully-functional working program(s) in executable form as well as complete source code of all work done.
2) Deliverables must be in ready-to-run condition, as follows (depending on the nature of the deliverables):
a) For web sites or other server-side deliverables intended to only ever exist in one place in the Buyer's environment--Deliverables must be installed by the Seller in ready-to-run condition in the Buyer's environment.
b) For all others including desktop software or software the buyer intends to distribute: A software installation package that will install the software in ready-to-run condition on the platform(s) specified in this bid request.
3) All deliverables will be considered "work made for hire" under U.S. Copyright law. Buyer will receive exclusive and complete copyrights to all work purchased. (No GPL, GNU, 3rd party components, etc. unless all copyright ramifications are explained AND AGREED TO by the buyer on the site per the coder's Seller Legal Agreement).
## Platform
w32