Subject Re: [firebird-support] Non null column, before insert trigger not filling column, Delphi
Author Michael Ludwig
Mike schrieb am 15.06.2010 um 10:28 (-0000):

> I have an 'ID' INTEGER column without a non-null constraint. The table
> has a BEFORE INSERT trigger that executes the generator that fills the
> column. When I post a new record the trigger fires and creates the ID
> column value correctly.
>
> However, if the 'ID' column has a non-null constraint when I post I
> get an error: 'Column ID must have a value'.
>
> I would have expected the trigger to have filled the column but
> apparently the constraint checking takes precedence.

This scenario works for me:

CREATE SEQUENCE USR_ID_SEQ ^

CREATE TABLE USR (
id INTEGER NOT NULL,
name VARCHAR(10) NOT NULL
) ^

CREATE TRIGGER USR_TRBI FOR USR
ACTIVE BEFORE INSERT
AS
BEGIN
IF ( NEW.id IS NULL ) THEN
NEW.ID = NEXT VALUE FOR USR_ID_SEQ;
END ^

Maybe you have to recompile something by doing a DROP/CREATE?

--
Michael Ludwig