
/* Table: IBO$DMLCACHE, Owner: SYSDBA */
CREATE TABLE IBO$DMLCACHE (DMLID INTEGER NOT NULL,
        DMLACTION CHAR(1) NOT NULL,
        KEYFIELDS VARCHAR(128) NOT NULL,
        KEYVALUE1 VARCHAR(128) NOT NULL,
        KEYVALUE2 VARCHAR(128),
        KEYVALUE3 VARCHAR(128),
        DMLUSER VARCHAR(32) NOT NULL,
PRIMARY KEY (DMLID));

CREATE GENERATOR IBO$DMLCACHE;

COMMIT WORK;

CREATE TRIGGER AI_IBO$DMLCACHE FOR IBO$DMLCACHE
ACTIVE AFTER INSERT POSITION 0
AS
BEGIN
  POST_EVENT 'IBO$DMLCACHE';
END;

CREATE TRIGGER BI_IBO$DMLCACHE FOR IBO$DMLCACHE
ACTIVE BEFORE INSERT POSITION 0
AS
BEGIN
  IF ( NEW.DMLID IS NULL ) THEN BEGIN
    NEW.DMLID = GEN_ID( IBO$DMLCACHE, 1 );
  END
  IF ( NEW.DMLUSER IS NULL ) THEN BEGIN
    NEW.DMLUSER = USER;
  END
END;

CREATE TRIGGER AU_SURVEY_IBO$DMLCACHE FOR TABLE_SURVEY
ACTIVE AFTER UPDATE POSITION 0
AS
BEGIN
  INSERT INTO IBO$DMLCACHE( DMLACTION, KEYFIELDS, KEYVALUE1 )
    VALUES ( 'U', 'SURVEYID', OLD.SURVEYID );
END;

CREATE TRIGGER AU_QUESTION_IBO$DMLCACHE FOR TABLE_QUESTION
ACTIVE AFTER UPDATE POSITION 0
AS
BEGIN
  INSERT INTO IBO$DMLCACHE( DMLACTION, KEYFIELDS, KEYVALUE1 )
    VALUES ( 'U', 'QUESTIONID', OLD.QUESTIONID );
END;

CREATE TRIGGER AI_SURVEY_IBO$DMLCACHE FOR TABLE_SURVEY
ACTIVE AFTER INSERT POSITION 0
AS
BEGIN
  INSERT INTO IBO$DMLCACHE( DMLACTION, KEYFIELDS, KEYVALUE1 )
    VALUES ( 'I', 'SURVEYID', NEW.SURVEYID );
END;

CREATE TRIGGER AD_SURVEY_IBO$DMLCACHE FOR TABLE_SURVEY
ACTIVE AFTER DELETE POSITION 0
AS
BEGIN
  INSERT INTO IBO$DMLCACHE( DMLACTION, KEYFIELDS, KEYVALUE1 )
    VALUES ( 'D', 'SURVEYID', OLD.SURVEYID );
END;

CREATE TRIGGER AI_QUESTION_IBO$DMLCACHE FOR TABLE_QUESTION
ACTIVE AFTER INSERT POSITION 0
AS
BEGIN
  INSERT INTO IBO$DMLCACHE( DMLACTION, KEYFIELDS, KEYVALUE1 )
    VALUES ( 'I', 'QUESTIONID', NEW.QUESTIONID );
END;

CREATE TRIGGER AD_QUESTION_IBO$DMLCACHE FOR TABLE_QUESTION
ACTIVE AFTER DELETE POSITION 0
AS
BEGIN
  INSERT INTO IBO$DMLCACHE( DMLACTION, KEYFIELDS, KEYVALUE1 )
    VALUES ( 'D', 'QUESTIONID', OLD.QUESTIONID );
END;

CREATE TRIGGER AU_SURVEY_QUESTION_IBO$DMLCACHE FOR TABLE_SURVEY_QUESTION
ACTIVE AFTER UPDATE POSITION 0
AS
BEGIN
  INSERT INTO IBO$DMLCACHE( DMLACTION, KEYFIELDS, KEYVALUE1, KEYVALUE2 )
    VALUES ( 'U', 'SURVEYID;QUESTIONID', OLD.SURVEYID, OLD.QUESTIONID );
END;

CREATE TRIGGER AD_SURVEY_QUESTION_IBO$DMLCACHE FOR TABLE_SURVEY_QUESTION
ACTIVE AFTER DELETE POSITION 0
AS
BEGIN
  INSERT INTO IBO$DMLCACHE( DMLACTION, KEYFIELDS, KEYVALUE1, KEYVALUE2 )
    VALUES ( 'D', 'SURVEYID;QUESTIONID', OLD.SURVEYID, OLD.QUESTIONID );
END;

CREATE TRIGGER AI_SURVEY_QUESTION_IBO$DMLCACHE FOR TABLE_SURVEY_QUESTION
ACTIVE AFTER INSERT POSITION 0
AS
BEGIN
  INSERT INTO IBO$DMLCACHE( DMLACTION, KEYFIELDS, KEYVALUE1, KEYVALUE2 )
    VALUES ( 'I', 'SURVEYID;QUESTIONID', NEW.SURVEYID, NEW.QUESTIONID );
END;

GRANT SELECT, INSERT ON IBO$DMLCACHE TO PUBLIC;

COMMIT WORK;