views:

30

answers:

1

In a Firebird database, I need to create a DOMAIN with default value taken from the context variable.

It should be something like

CREATE DOMAIN USER_ID AS INTEGER 
  DEFAULT RDB$GET_CONTEXT('USER_SESSION','UID') NOT NULL;

When I execute this, I am getting the following error

Invalid token.
Dynamic SQL Error.
SQL error code = -104.
Token unknown - line 2, column 13.
RDB$GET_CONTEXT.

How can this be done, maybe there is another way than the DEFAULT clause?

+2  A: 

Just create a BEFORE INSERT trigger:

CREATE TRIGGER your_trigger_name FOR your_table
  BEFORE INSERT
  POSITION 0
AS
BEGIN
  IF (NEW.your_field IS NULL) THEN
    NEW.your_field = RDB$GET_CONTEXT('USER_SESSION','UID'); 
END
Andrei K.
Thanks I wanted to not have to create a trigger for each table. Firebird does not support this. Thanks