Subject Firebird 1.5 RC5 Trigger Exception Handlers allow Unique Key Violations
Author kumasoftllc
During testing of Firebird 1.5 RC5 I have discovered that exception
handlers in triggers will allow violations to Unique Key Constraints,
even though a message to the contrary is displayed.

Here is a script to duplicate the problem:

create Table DupeUniqueKeysTab
(
col1 int not null,
col2 varchar(10),
constraint DupeUniqueKeysTab_pk Primary Key (col1),
constraint DupeUniqueKeysTab_uk Unique (col2)
);

create trigger DupeUniqueKeysTab_v_rbi for DupeUniqueKeysTab
active before insert position 100
AS

BEGIN

new.col2 = upper(new.col2);

exit;

when gdscode DEADLOCK do
BEGIN
/* Do nothing */
END


END;

insert into DupeUniqueKeysTab(col1, col2) values (1, 'Hello');

commit;

insert into DupeUniqueKeysTab(col1, col2) values (2, 'Hello');

commit;

When the second insert statement is issued, the following error
message will result:

Invalid insert or update value(s): object columns are
constrained - no 2 table rows can have duplicate column values.
violation of PRIMARY or UNIQUE KEY constraint "DUPEUNIQUEKEYSTAB_PK"
on table "DUPEUNIQUEKEYSTAB".

However, performing the commit and querying the table will reveal
that the table now contains 2 records.

If the exception handler is removed from the trigger and the test re-
run, the result will be as expected...a single record in the table.

Bob