-- @@@ START COPYRIGHT @@@
--
-- Licensed to the Apache Software Foundation (ASF) under one
-- or more contributor license agreements.  See the NOTICE file
-- distributed with this work for additional information
-- regarding copyright ownership.  The ASF licenses this file
-- to you under the Apache License, Version 2.0 (the
-- "License"); you may not use this file except in compliance
-- with the License.  You may obtain a copy of the License at
--
--   http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing,
-- software distributed under the License is distributed on an
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-- KIND, either express or implied.  See the License for the
-- specific language governing permissions and limitations
-- under the License.
--
-- @@@ END COPYRIGHT @@@
--
-- Ensures that the insert into the temporary table is using the SYSKEY column
-- of the subject table as the value for its "@SYSKEY" column.
--

set schema CAT1.SCHM;
set parserflags 1;
obey TEST_2_3_5(clean_up);
log LOG_2_3_5 clear;
obey TEST_2_3_5(set_up);
obey TEST_2_3_5(tests);
obey TEST_2_3_5(clean_up);
log;
exit;

----------------------------------------

?section clean_up
DROP TRIGGER TR_INS_2_3_5;
DROP TRIGGER TR_UPD_2_3_5;
DROP TRIGGER TR_DEL_2_3_5;
DROP TABLE T1_2_3_5;
obey clearTables2;

?section set_up
create table t1_2_3_5(olda int, oldb int, newa int, newb int, event char(20));

create trigger TR_INS_2_3_5
after insert on T1
referencing new as newr
for each row
insert into t1_2_3_5 values (0, 0, newr.a, newr.b, 'inserted');

create trigger TR_UPD_2_3_5
after update on T1
referencing old as oldr, new as newr
for each row
insert into t1_2_3_5 values (oldr.a, oldr.b, newr.a, newr.b, 'updated');

create trigger TR_DEL_2_3_5
after delete on T1
referencing old as oldr
for each row
insert into t1_2_3_5 values (oldr.a, oldr.b, 0, 0, 'deleted');

?section tests
showddl T1;
showddl table(temp_table T1__TEMP);

insert into t1 values (1,1),(1,2),(1,3);
update t1 set b=-b where b=3;
delete from t1 where b=1;

SELECT * FROM T1 ORDER BY SYSKEY;
SELECT * FROM T1_2_3_5 ORDER BY SYSKEY;
