Subject Inserting into TIBOTable?
Author jacobhavkrog
Hi, migrating from BDE to Firebird, and I've got this table

CREATE TABLE LOG (
LogNo INT,
UserNo INT NOT NULL,
LogType INT NOT NULL,
LogTimeStamp TIMESTAMP,
PRIMARY KEY (LogNo)
);

with trigger

SELECT MAX(LogNo) FROM LOG
CREATE SEQUENCE LogNo_LOG_GEN
SET GENERATOR LogNo_LOG_GEN TO 4120;
CREATE TRIGGER LogNo_LOG_TRIG FOR LOG
BEFORE INSERT
AS
BEGIN
NEW.LogNo = GEN_ID(LogNo_LOG_GEN, 1);
END

Now, when I from my Delphi code insert a record, like

LogTable: TIBOTable;
...
LogTable.Open;
LogTable.Insert;
LogTableUserNo.Value := AUserNo;
LogTableLogType.Value := Ord(ALogType);
LogTableLogTimeStamp.Value := Now;
LogTable.Post;

I get this error message "Field LOGNO must have a value".

If I set

LogTableLogNo.Required := False;

before the Insert statement, then the error goes away.

Do I really need to do this? Or am I doing something wrong here? It seems the trigger is triggering too late?


Bonus question - whats the point of the line

SELECT MAX(LogNo) FROM LOG

in the script creating the trigger, when that number 4120 is occurs as a constant just below?

THANKS
Jacob :-)