-- Version:		2025.7.31  14:52:27
Drop Table T_HMI_HEADER@

Create Table T_HMI_HEADER(
name		VARCHAR(80)		NOT NULL,
sequence		DECIMAL(8)		NOT NULL,
chinese		VARCHAR(36),
items		VARCHAR(200),
width		DECIMAL(10),
flag		DECIMAL(8),
fixed		DECIMAL(8),
background		VARCHAR(50),
datasource		VARCHAR(50),
toc		TIMESTAMP,
tom		TIMESTAMP,
mop		VARCHAR(120),
mou		VARCHAR(30),
CONSTRAINT pk_T_HMI_HEADER PRIMARY KEY (name, sequence)
)
IN TB8KUSREMS INDEX IN TB8KIDXEMS@

COMMENT ON Table T_HMI_HEADER IS '设备可视化模板表头'@

COMMENT ON T_HMI_HEADER (name IS '表名英文')@
COMMENT ON T_HMI_HEADER (sequence IS '列次序')@
COMMENT ON T_HMI_HEADER (chinese IS '表名中文')@
COMMENT ON T_HMI_HEADER (items IS '列名中文')@
COMMENT ON T_HMI_HEADER (width IS '列尺寸')@
COMMENT ON T_HMI_HEADER (flag IS '列类型:1-普通数据/2-跳转按钮/3-mq按钮')@
COMMENT ON T_HMI_HEADER (fixed IS '列属性：0-不固定/1-固定')@
COMMENT ON T_HMI_HEADER (background IS '列填充色')@
COMMENT ON T_HMI_HEADER (datasource IS '列数据源')@

/****************************************************************************
						INSERT TRIGGER FOR TABLE
							  T_HMI_HEADER
*****************************************************************************/
DROP TRIGGER ins_b_T_HMI_HEADER@

CREATE OR REPLACE TRIGGER ins_b_T_HMI_HEADER
BEFORE INSERT ON T_HMI_HEADER REFERENCING NEW AS NEWROW FOR EACH ROW
MODE DB2SQL
BEGIN ATOMIC
	DECLARE	programm	VARCHAR(120);
	DECLARE	auth	VARCHAR(30);

	set (programm,auth) = (SELECT APPL_NAME,AUTHID FROM SYSIBMADM.APPLICATIONS WHERE APPL_ID = (SELECT APPLICATION_ID() FROM dual));

	set NEWROW.toc = (values sysdate);
	set NEWROW.tom = (values sysdate);
	set NEWROW.mop = programm;
	set NEWROW.mou = auth;
END
@
/****************************************************************************
						UPDATE TRIGGER FOR TABLE
							  T_HMI_HEADER
*****************************************************************************/
DROP TRIGGER upd_b_T_HMI_HEADER@

CREATE OR REPLACE TRIGGER upd_b_T_HMI_HEADER
BEFORE UPDATE ON T_HMI_HEADER REFERENCING NEW AS NEWROW FOR EACH ROW
MODE DB2SQL
BEGIN ATOMIC
	DECLARE	programm	VARCHAR(120);
	DECLARE	auth	VARCHAR(30);

	set (programm,auth) = (SELECT APPL_NAME,AUTHID FROM SYSIBMADM.APPLICATIONS WHERE APPL_ID = (SELECT APPLICATION_ID() FROM dual));

	set NEWROW.tom = (values sysdate);
	set NEWROW.mop = programm;
	set NEWROW.mou = auth;
END
@
