2004-08-20 12:57:18 +02:00
|
|
|
CREATE GENERATOR CHANGE_NUM;
|
|
|
|
|
|
|
|
/* Domain definitions */
|
|
|
|
CREATE DOMAIN D_ACTION AS BLOB SUB_TYPE 0 SEGMENT SIZE 0;
|
|
|
|
CREATE DOMAIN CHANGE_DATE AS TIMESTAMP;
|
|
|
|
CREATE DOMAIN CHANGE_NUMBER AS INTEGER;
|
|
|
|
CREATE DOMAIN CHANGE_WHO AS VARCHAR(32);
|
|
|
|
CREATE DOMAIN CLASS AS CHAR(10);
|
|
|
|
CREATE DOMAIN DESCRIPTION AS BLOB SUB_TYPE 0 SEGMENT SIZE 80;
|
|
|
|
CREATE DOMAIN EXPLANATION AS BLOB SUB_TYPE 0 SEGMENT SIZE 0;
|
|
|
|
CREATE DOMAIN FACILITY AS CHAR(10);
|
|
|
|
CREATE DOMAIN FAC_CODE AS SMALLINT;
|
|
|
|
CREATE DOMAIN D_FILE AS VARCHAR(30);
|
|
|
|
CREATE DOMAIN FLAGS AS SMALLINT;
|
|
|
|
CREATE DOMAIN LANGUAGE AS VARCHAR(10);
|
|
|
|
CREATE DOMAIN LAST_CHANGE AS TIMESTAMP;
|
|
|
|
CREATE DOMAIN LOCALE AS VARCHAR(20);
|
|
|
|
CREATE DOMAIN MAX_NUMBER AS SMALLINT;
|
|
|
|
CREATE DOMAIN MODULE AS VARCHAR(32);
|
|
|
|
CREATE DOMAIN NUMBER AS SMALLINT;
|
|
|
|
CREATE DOMAIN OLD_SEQUENCE AS SMALLINT;
|
|
|
|
CREATE DOMAIN ROUTINE AS VARCHAR(32);
|
|
|
|
CREATE DOMAIN SEQUENCE AS SMALLINT;
|
|
|
|
CREATE DOMAIN SEVERITY AS SMALLINT;
|
|
|
|
CREATE DOMAIN SEVERITY_TEXT AS CHAR(7);
|
|
|
|
CREATE DOMAIN SQL_CLASS AS CHAR(2);
|
|
|
|
CREATE DOMAIN SQL_CODE AS SMALLINT;
|
2008-02-24 15:07:01 +01:00
|
|
|
CREATE DOMAIN SQL_STATE AS CHAR(5);
|
2004-08-20 12:57:18 +02:00
|
|
|
CREATE DOMAIN SQL_SUBCLASS AS CHAR(3);
|
|
|
|
CREATE DOMAIN SYMBOL AS VARCHAR(32);
|
|
|
|
CREATE DOMAIN TEMPLATE AS BLOB SUB_TYPE 0 SEGMENT SIZE 256;
|
|
|
|
CREATE DOMAIN TEXT AS VARCHAR(118);
|
|
|
|
CREATE DOMAIN TRANSLATOR AS VARCHAR(32);
|
|
|
|
CREATE DOMAIN TRANS_DATE AS TIMESTAMP;
|
|
|
|
CREATE DOMAIN TRANS_NOTES AS BLOB SUB_TYPE 0 SEGMENT SIZE 0;
|
|
|
|
CREATE DOMAIN D_TYPE AS CHAR(12);
|
|
|
|
CREATE DOMAIN D_VALUE AS INTEGER;
|
|
|
|
|
|
|
|
COMMIT;
|
|
|
|
|
|
|
|
/* Tables */
|
|
|
|
|
|
|
|
CREATE TABLE FACILITIES (
|
|
|
|
LAST_CHANGE LAST_CHANGE,
|
2004-10-25 12:28:46 +02:00
|
|
|
FACILITY FACILITY NOT NULL CONSTRAINT FAC_2 UNIQUE,
|
2004-08-20 12:57:18 +02:00
|
|
|
FAC_CODE FAC_CODE NOT NULL CONSTRAINT FAC_1 PRIMARY KEY,
|
|
|
|
MAX_NUMBER MAX_NUMBER
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE HISTORY (
|
2004-11-24 10:00:29 +01:00
|
|
|
CHANGE_NUMBER CHANGE_NUMBER NOT NULL CONSTRAINT HIS_1 PRIMARY KEY,
|
|
|
|
CHANGE_WHO CHANGE_WHO NOT NULL,
|
|
|
|
CHANGE_DATE CHANGE_DATE NOT NULL,
|
|
|
|
FAC_CODE FAC_CODE NOT NULL /*REFERENCES FACILITIES*/,
|
|
|
|
NUMBER NUMBER NOT NULL,
|
2004-08-20 12:57:18 +02:00
|
|
|
OLD_TEXT TEXT,
|
|
|
|
OLD_ACTION D_ACTION,
|
|
|
|
OLD_EXPLANATION EXPLANATION,
|
|
|
|
LOCALE LOCALE,
|
2008-02-24 15:07:01 +01:00
|
|
|
CODE COMPUTED BY (FAC_CODE * 10000 + NUMBER)
|
2004-08-20 12:57:18 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE LOCALES (
|
|
|
|
LOCALE LOCALE NOT NULL CONSTRAINT PRIMARY_LOCALES PRIMARY KEY,
|
|
|
|
DESCRIPTION DESCRIPTION
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE MESSAGES (
|
2008-03-07 08:37:57 +01:00
|
|
|
SYMBOL SYMBOL CONSTRAINT MSGSYMBOL UNIQUE,
|
2004-08-20 12:57:18 +02:00
|
|
|
ROUTINE ROUTINE,
|
|
|
|
MODULE MODULE,
|
|
|
|
TRANS_NOTES TRANS_NOTES,
|
2004-11-19 04:52:43 +01:00
|
|
|
FAC_CODE FAC_CODE NOT NULL REFERENCES FACILITIES,
|
2004-10-25 12:28:46 +02:00
|
|
|
NUMBER NUMBER NOT NULL,
|
2004-08-20 12:57:18 +02:00
|
|
|
FLAGS FLAGS,
|
2008-03-07 08:37:57 +01:00
|
|
|
TEXT TEXT NOT NULL,
|
2004-08-20 12:57:18 +02:00
|
|
|
"ACTION" D_ACTION,
|
|
|
|
EXPLANATION EXPLANATION,
|
2008-02-24 15:07:01 +01:00
|
|
|
CODE COMPUTED BY (FAC_CODE * 10000 + NUMBER),
|
2008-03-07 08:37:57 +01:00
|
|
|
CONSTRAINT MESSAGES_PK PRIMARY KEY (FAC_CODE, NUMBER),
|
|
|
|
CONSTRAINT CNS UNIQUE (FAC_CODE, NUMBER, SYMBOL)
|
2008-02-24 15:07:01 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE SQLSTATES (
|
|
|
|
SQL_CLASS SQL_CLASS NOT NULL,
|
|
|
|
SQL_SUBCLASS SQL_SUBCLASS DEFAULT '000' NOT NULL,
|
|
|
|
SQL_STATE COMPUTED BY (CAST(SQL_CLASS || SQL_SUBCLASS AS SQL_STATE)),
|
2008-03-07 08:37:57 +01:00
|
|
|
SQL_STATE_TEXT TEXT NOT NULL,
|
2008-02-24 15:07:01 +01:00
|
|
|
CONSTRAINT SQLSTATES_PK PRIMARY KEY (SQL_CLASS, SQL_SUBCLASS)
|
2004-08-20 12:57:18 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE SYMBOLS (
|
|
|
|
SYMBOL SYMBOL NOT NULL CONSTRAINT SYM2 PRIMARY KEY,
|
|
|
|
"VALUE" D_VALUE,
|
|
|
|
CLASS CLASS,
|
|
|
|
"TYPE" D_TYPE,
|
|
|
|
SEQUENCE SEQUENCE
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE SYSTEM_ERRORS (
|
2008-03-07 08:37:57 +01:00
|
|
|
SQL_CODE SQL_CODE NOT NULL,
|
|
|
|
SQL_CLASS SQL_CLASS NOT NULL,
|
|
|
|
SQL_SUBCLASS SQL_SUBCLASS NOT NULL,
|
2004-11-19 04:52:43 +01:00
|
|
|
FAC_CODE FAC_CODE NOT NULL REFERENCES FACILITIES,
|
2007-03-28 06:49:35 +02:00
|
|
|
NUMBER NUMBER NOT NULL,
|
2004-10-25 12:28:46 +02:00
|
|
|
GDS_SYMBOL SYMBOL NOT NULL CONSTRAINT SYSERR2 UNIQUE,
|
2004-08-20 12:57:18 +02:00
|
|
|
SEVERITY SEVERITY,
|
|
|
|
SEVERITY_TEXT SEVERITY_TEXT,
|
|
|
|
CODE COMPUTED BY (FAC_CODE * 10000 + NUMBER),
|
2008-02-24 15:07:01 +01:00
|
|
|
SQL_STATE COMPUTED BY (CAST(SQL_CLASS || SQL_SUBCLASS AS SQL_STATE)),
|
2008-03-07 08:37:57 +01:00
|
|
|
CONSTRAINT SYSTEM_ERRORS_PK PRIMARY KEY (FAC_CODE, NUMBER),
|
|
|
|
CONSTRAINT SQL_STATE_FK FOREIGN KEY (SQL_CLASS, SQL_SUBCLASS) REFERENCES SQLSTATES (SQL_CLASS, SQL_SUBCLASS),
|
|
|
|
--CONSTRAINT SYMBOL_FK FOREIGN KEY (GDS_SYMBOL) REFERENCES MESSAGES (SYMBOL)
|
|
|
|
CONSTRAINT CNS_FK FOREIGN KEY (FAC_CODE, NUMBER, GDS_SYMBOL)
|
|
|
|
REFERENCES MESSAGES (FAC_CODE, NUMBER, SYMBOL)
|
2004-08-20 12:57:18 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE TEMPLATES (
|
|
|
|
LANGUAGE LANGUAGE,
|
|
|
|
"FILE" D_FILE,
|
|
|
|
TEMPLATE TEMPLATE
|
|
|
|
);
|
|
|
|
|
|
|
|
COMMIT;
|
|
|
|
|
|
|
|
CREATE TABLE TRANSMSGS (
|
|
|
|
ENG_TEXT TEXT,
|
|
|
|
ENG_ACTION D_ACTION,
|
|
|
|
ENG_EXPLANATION EXPLANATION,
|
2008-03-07 08:37:57 +01:00
|
|
|
FAC_CODE FAC_CODE NOT NULL, -- REFERENCES FACILITIES, redundant, see FULLCODE_FK
|
2004-10-25 12:28:46 +02:00
|
|
|
NUMBER NUMBER NOT NULL,
|
2008-03-07 08:37:57 +01:00
|
|
|
LOCALE LOCALE NOT NULL CONSTRAINT LOCALE_FK REFERENCES LOCALES,
|
|
|
|
TEXT TEXT NOT NULL,
|
2004-08-20 12:57:18 +02:00
|
|
|
"ACTION" D_ACTION,
|
|
|
|
EXPLANATION EXPLANATION,
|
|
|
|
TRANSLATOR TRANSLATOR,
|
|
|
|
TRANS_DATE TRANS_DATE,
|
2008-02-24 15:07:01 +01:00
|
|
|
CODE COMPUTED BY (FAC_CODE * 10000 + NUMBER),
|
2008-03-07 08:37:57 +01:00
|
|
|
CONSTRAINT TRANSMSGS_PK PRIMARY KEY (LOCALE, FAC_CODE, NUMBER),
|
|
|
|
CONSTRAINT FULLCODE_FK FOREIGN KEY (FAC_CODE, NUMBER) REFERENCES MESSAGES (FAC_CODE, NUMBER)
|
2004-08-20 12:57:18 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
COMMIT;
|
|
|
|
|
|
|
|
/* Index definitions for all user tables */
|
|
|
|
CREATE INDEX SYM1 ON SYMBOLS(CLASS, "TYPE");
|
|
|
|
|
|
|
|
COMMIT;
|
|
|
|
|
|
|
|
SET TERM ^ ;
|
|
|
|
|
|
|
|
/* Triggers */
|
|
|
|
CREATE TRIGGER FACILITIES$STORE FOR FACILITIES
|
2004-10-25 12:28:46 +02:00
|
|
|
ACTIVE BEFORE INSERT POSITION 0 AS
|
2004-08-20 12:57:18 +02:00
|
|
|
begin
|
|
|
|
new.last_change = CURRENT_TIMESTAMP;
|
|
|
|
end^
|
2004-10-25 12:28:46 +02:00
|
|
|
|
|
|
|
CREATE TRIGGER FACILITIES$MODIFY FOR FACILITIES
|
|
|
|
ACTIVE BEFORE UPDATE POSITION 0 AS
|
|
|
|
begin
|
|
|
|
new.last_change = CURRENT_TIMESTAMP;
|
|
|
|
end^
|
|
|
|
|
2004-08-20 12:57:18 +02:00
|
|
|
CREATE TRIGGER MESSAGES$MODIFY FOR MESSAGES
|
|
|
|
ACTIVE AFTER UPDATE POSITION 0 AS
|
|
|
|
begin
|
|
|
|
update facilities
|
|
|
|
set last_change = current_timestamp
|
|
|
|
where fac_code = new.fac_code;
|
|
|
|
end^
|
|
|
|
|
|
|
|
CREATE TRIGGER MSGS$MODIFY FOR MESSAGES
|
|
|
|
ACTIVE AFTER UPDATE POSITION 1 AS
|
|
|
|
begin
|
|
|
|
if (new.text <> old.text) then
|
|
|
|
begin
|
|
|
|
insert into history (change_number, change_date, change_who, fac_code,
|
|
|
|
number, old_text, old_action, old_explanation, locale)
|
|
|
|
values (gen_id(change_num, 1), current_timestamp, current_user,
|
|
|
|
old.fac_code, old.number, old.text, old."ACTION",
|
|
|
|
old.explanation, 'c_pg');
|
|
|
|
end
|
|
|
|
end^
|
|
|
|
|
|
|
|
CREATE TRIGGER TRANSMSGS$STORE FOR TRANSMSGS
|
|
|
|
ACTIVE BEFORE INSERT POSITION 0 AS
|
|
|
|
begin
|
|
|
|
if (new.translator is NULL) then
|
|
|
|
new.translator = current_user;
|
|
|
|
if (new.trans_date is NULL) then
|
|
|
|
new.trans_date = current_timestamp;
|
|
|
|
end^
|
|
|
|
|
|
|
|
CREATE TRIGGER TRANSMSGS$MODIFY FOR TRANSMSGS
|
|
|
|
ACTIVE AFTER UPDATE POSITION 0 AS
|
|
|
|
begin
|
|
|
|
if (new.text <> old.text) then
|
|
|
|
begin
|
|
|
|
insert into history (change_number, change_date, change_who, fac_code,
|
|
|
|
number, old_text, old_action, old_explanation, locale)
|
|
|
|
values (gen_id(change_num, 1), current_timestamp, current_user,
|
|
|
|
old.fac_code, old.number, old.text, old."ACTION",
|
|
|
|
old.explanation, old.locale);
|
|
|
|
end
|
|
|
|
end^
|
|
|
|
|
|
|
|
COMMIT^
|
|
|
|
SET TERM ; ^
|
2007-03-12 12:49:05 +01:00
|
|
|
|
|
|
|
-- Grant permission to the general audience to read these tables.
|
|
|
|
GRANT SELECT ON FACILITIES TO PUBLIC;
|
|
|
|
GRANT SELECT ON HISTORY TO PUBLIC;
|
|
|
|
GRANT SELECT ON LOCALES TO PUBLIC;
|
|
|
|
GRANT SELECT ON MESSAGES TO PUBLIC;
|
|
|
|
GRANT SELECT ON SYMBOLS TO PUBLIC;
|
|
|
|
GRANT SELECT ON SYSTEM_ERRORS TO PUBLIC;
|
|
|
|
GRANT SELECT ON TEMPLATES TO PUBLIC;
|
|
|
|
GRANT SELECT ON TRANSMSGS TO PUBLIC;
|
|
|
|
|
|
|
|
COMMIT;
|
|
|
|
|