Subject Re: variable not updating in SP
Author csswa
Here is a snippet of output from my procedure that autocreates about
a hundred logging triggers. This demonstrates the correct result of
the :var_pkname issue. The lines that were 'stuck' prior to the IN
fix were those similar to (VAR_TOPT_PK, NEW.ACT_PK,'I');

The external table definition:

CREATE TABLE T_EXT_TRIGGER_SCRIPTS EXTERNAL FILE 'C:\TRIGGERS.SQL' (
LINEDATA CHAR(78),
NEWLINE CHAR(2) DEFAULT ''
)^

The line-by-line view of the data in the table, loaded into a text
editor:

SET TERM^;
CREATE TRIGGER TR_ACTION_LOG_AI FOR T_ACTION
ACTIVE AFTER INSERT POSITION 10000
AS
DECLARE VARIABLE VAR_TOPT_PK SMALLINT;
BEGIN
SELECT TOPT_PK
FROM T_TABLE_OPTIONS
WHERE TOPT_TABLE_NAME = 'T_ACTION'
INTO :VAR_TOPT_PK;
EXECUTE PROCEDURE SP_LOG_CHANGES
(VAR_TOPT_PK, NEW.ACT_PK,'I');
END^
SET TERM;^
SET TERM^;
CREATE TRIGGER TR_ACTION_LOG_AU FOR T_ACTION
ACTIVE AFTER UPDATE POSITION 10000
AS
DECLARE VARIABLE VAR_TOPT_PK SMALLINT;
BEGIN
SELECT TOPT_PK
FROM T_TABLE_OPTIONS
WHERE TOPT_TABLE_NAME = 'T_ACTION'
INTO :VAR_TOPT_PK;
EXECUTE PROCEDURE SP_LOG_CHANGES
(VAR_TOPT_PK, NEW.ACT_PK,'U');
END^
SET TERM;^
SET TERM^;
CREATE TRIGGER TR_ACTION_LOG_BD FOR T_ACTION
ACTIVE BEFORE DELETE POSITION 10000
AS
DECLARE VARIABLE VAR_TOPT_PK SMALLINT;
BEGIN
SELECT TOPT_PK
FROM T_TABLE_OPTIONS
WHERE TOPT_TABLE_NAME = 'T_ACTION'
INTO :VAR_TOPT_PK;
EXECUTE PROCEDURE SP_LOG_CHANGES
(VAR_TOPT_PK, OLD.ACT_PK,'D');
END^
SET TERM;^
SET TERM^;
CREATE TRIGGER TR_ACTION_NO_DELETE FOR T_ACTION
ACTIVE BEFORE DELETE POSITION 0
AS
BEGIN
IF ( NOT EXISTS ( SELECT 1 FROM T_TABLE_OPTIONS
WHERE (TOPT_TABLE_NAME = 'T_ACTION')
AND (TOPT_ALLOW_DELETE = 'Y') ) ) THEN EXCEPTION E_NO_DELETE;
END^
SET TERM;^
SET TERM^;
CREATE TRIGGER TR_ADDRESS_LOG_AI FOR T_ADDRESS
ACTIVE AFTER INSERT POSITION 10000
AS
DECLARE VARIABLE VAR_TOPT_PK SMALLINT;
BEGIN
SELECT TOPT_PK
FROM T_TABLE_OPTIONS
WHERE TOPT_TABLE_NAME = 'T_ADDRESS'
INTO :VAR_TOPT_PK;
EXECUTE PROCEDURE SP_LOG_CHANGES
(VAR_TOPT_PK, NEW.ADDR_PK,'I');
END^
SET TERM;^
SET TERM^;
CREATE TRIGGER TR_ADDRESS_LOG_AU FOR T_ADDRESS
ACTIVE AFTER UPDATE POSITION 10000
AS
DECLARE VARIABLE VAR_TOPT_PK SMALLINT;
BEGIN
SELECT TOPT_PK
FROM T_TABLE_OPTIONS
WHERE TOPT_TABLE_NAME = 'T_ADDRESS'
INTO :VAR_TOPT_PK;
EXECUTE PROCEDURE SP_LOG_CHANGES
(VAR_TOPT_PK, NEW.ADDR_PK,'U');
END^
SET TERM;^
SET TERM^;
CREATE TRIGGER TR_ADDRESS_LOG_BD FOR T_ADDRESS
ACTIVE BEFORE DELETE POSITION 10000
AS
DECLARE VARIABLE VAR_TOPT_PK SMALLINT;
BEGIN
SELECT TOPT_PK
FROM T_TABLE_OPTIONS
WHERE TOPT_TABLE_NAME = 'T_ADDRESS'
INTO :VAR_TOPT_PK;
EXECUTE PROCEDURE SP_LOG_CHANGES
(VAR_TOPT_PK, OLD.ADDR_PK,'D');
END^
SET TERM;^
SET TERM^;
CREATE TRIGGER TR_ADDRESS_NO_DELETE FOR T_ADDRESS
ACTIVE BEFORE DELETE POSITION 0
AS
BEGIN
IF ( NOT EXISTS ( SELECT 1 FROM T_TABLE_OPTIONS
WHERE (TOPT_TABLE_NAME = 'T_ADDRESS')
AND (TOPT_ALLOW_DELETE = 'Y') ) ) THEN EXCEPTION E_NO_DELETE;
END^
SET TERM;^
SET TERM^;

...etc. looping through entire table list:

T_ACTION
T_ADDRESS
T_AUTOEVAL
T_CODESET
... etc. through to
T_UNIT_NAME

Regards,
Andrew Ferguson