SET SQL DIALECT 3;



/******************************************************************************/
/****                               Domains                                ****/
/******************************************************************************/

CREATE DOMAIN BLOBTEXT AS
BLOB SUB_TYPE 1 SEGMENT SIZE 80;

CREATE DOMAIN DATECOMPLETE AS
TIMESTAMP;

CREATE DOMAIN DATECOMPLETE2 AS
TIMESTAMP
DEFAULT 'now'
NOT NULL;

CREATE DOMAIN ENTIER AS
INTEGER
DEFAULT 0;

CREATE DOMAIN IDENT AS
VARCHAR(22) CHARACTER SET NONE
NOT NULL;

CREATE DOMAIN LIB500 AS
VARCHAR(500);

CREATE DOMAIN REFERENCE AS
VARCHAR(22) CHARACTER SET NONE
DEFAULT '-1';




/******************************************************************************/
/****                                Tables                                ****/
/******************************************************************************/



CREATE TABLE BUPDATERLINKS (
    IDBUPDATERLINKS  IDENT /* IDENT = VARCHAR(22) NOT NULL */,
    BULREFPARENT     REFERENCE /* REFERENCE = VARCHAR(22) DEFAULT '-1' */,
    BULTYPE          ENTIER /* ENTIER = INTEGER DEFAULT 0 */,
    BULREFBYTYPE     REFERENCE /* REFERENCE = VARCHAR(22) DEFAULT '-1' */,
    BULDEST          LIB500 /* LIB500 = VARCHAR(500) */,
    BULJSON          BLOBTEXT /* BLOBTEXT = BLOB SUB_TYPE 1 SEGMENT SIZE 80 */,
    BULSTATE         ENTIER /* ENTIER = INTEGER DEFAULT 0 */,
    BULDATEACTION    DATECOMPLETE /* DATECOMPLETE = TIMESTAMP */,
    BULACTIF         ENTIER /* ENTIER = INTEGER DEFAULT 0 */,
    FTPDATE          DATECOMPLETE2 /* DATECOMPLETE2 = TIMESTAMP DEFAULT 'now' NOT NULL */,
    CREATEDATE       DATECOMPLETE2 /* DATECOMPLETE2 = TIMESTAMP DEFAULT 'now' NOT NULL */
);




/******************************************************************************/
/****                             Primary Keys                             ****/
/******************************************************************************/

ALTER TABLE BUPDATERLINKS ADD CONSTRAINT PK_BUPDATERLINKS PRIMARY KEY (IDBUPDATERLINKS);


/******************************************************************************/
/****                               Triggers                               ****/
/******************************************************************************/


SET TERM ^ ;



/******************************************************************************/
/****                         Triggers for tables                          ****/
/******************************************************************************/



/* Trigger: BUPDATERLINKS_BI */
CREATE OR ALTER TRIGGER BUPDATERLINKS_BI FOR BUPDATERLINKS
ACTIVE BEFORE INSERT POSITION 0
as
begin
  IF (NEW.idbupdaterlinks IS NULL) THEN
  BEGIN
    EXECUTE PROCEDURE SYS_GET_UUID RETURNING_VALUES NEW.idbupdaterlinks;
  END
end
^