Hello @all!
i am trying to create a trigger in db2 databas v7.
my create trigger statement is as follows:
[CODE=SQL]
create trigger TRI_TUSER_PWCHA NGE AFTER UPDATE
OF PASSWORD ON TUSER
REFERENCING NEW AS NEWVALUE OLD AS OLDVALUE
FOR each ROW
MODE db2sql
when ( OLDVALUE.ENCRYP TED = NEWVALUE.ENCRYP TED )
begin atomic
update tuser set LASTPASSWORDCHA NGE = CURRENT TIMESTAMP
where id_user = OLDVALUE.ID_USE R;
insert into TPASSWORDHISTOR Y (ID, ID_USER, CHANGEDATE, PASSWORD, ENCRYPTED) values
(NEXTVAL FOR S_ID_PASSWORDHI STORY, OLDVALUE.ID_USE R, CURRENT TIMESTAMP, OLDVALUE.PASSWO RD, OLDVALUE.ENCRYP TED);
delete from tpasswordhistor y where ID in
(
select ID from
(
select ROW_NUMBER() OVER (ORDER BY changedate desc) as rnum, ID, id_user, changedate from tpasswordhistor y
WHERE id_user = OLDVALUE.ID_USE R -- <----- that does not work!?
) as tmp1,
(
select CAST(value AS DECIMAL) as VALUE from tparameter where name = 'PasswordHistor yLength'
) as tmp2
where tmp1.rnum > tmp2.value
);
end
/
[/CODE]
when i execute the above statement, i get the following error:
"OLDVALUE.ID_US ER" is not defined name. SQLSTATE=42704
when i replace OLDVALUE.ID_USE R (in the third statement) with an absolute value for ID_USER, e.g. 1, then the trigger is created properly.
it seems that the scope of the NEW as ALIAS_NEW and OLD as ALIAS_OLD variables do not go beyond SubSubStatement s, e.g.:
delete from (
select * from (
select * from ... where X = NEW.VALUE
i would appreciate any help or comments, best regards daniel
ps: sorry for my bad english ;)
i am trying to create a trigger in db2 databas v7.
my create trigger statement is as follows:
[CODE=SQL]
create trigger TRI_TUSER_PWCHA NGE AFTER UPDATE
OF PASSWORD ON TUSER
REFERENCING NEW AS NEWVALUE OLD AS OLDVALUE
FOR each ROW
MODE db2sql
when ( OLDVALUE.ENCRYP TED = NEWVALUE.ENCRYP TED )
begin atomic
update tuser set LASTPASSWORDCHA NGE = CURRENT TIMESTAMP
where id_user = OLDVALUE.ID_USE R;
insert into TPASSWORDHISTOR Y (ID, ID_USER, CHANGEDATE, PASSWORD, ENCRYPTED) values
(NEXTVAL FOR S_ID_PASSWORDHI STORY, OLDVALUE.ID_USE R, CURRENT TIMESTAMP, OLDVALUE.PASSWO RD, OLDVALUE.ENCRYP TED);
delete from tpasswordhistor y where ID in
(
select ID from
(
select ROW_NUMBER() OVER (ORDER BY changedate desc) as rnum, ID, id_user, changedate from tpasswordhistor y
WHERE id_user = OLDVALUE.ID_USE R -- <----- that does not work!?
) as tmp1,
(
select CAST(value AS DECIMAL) as VALUE from tparameter where name = 'PasswordHistor yLength'
) as tmp2
where tmp1.rnum > tmp2.value
);
end
/
[/CODE]
when i execute the above statement, i get the following error:
"OLDVALUE.ID_US ER" is not defined name. SQLSTATE=42704
when i replace OLDVALUE.ID_USE R (in the third statement) with an absolute value for ID_USER, e.g. 1, then the trigger is created properly.
it seems that the scope of the NEW as ALIAS_NEW and OLD as ALIAS_OLD variables do not go beyond SubSubStatement s, e.g.:
delete from (
select * from (
select * from ... where X = NEW.VALUE
i would appreciate any help or comments, best regards daniel
ps: sorry for my bad english ;)
Comment