-- @@@ 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 @@@
-- RIs - triggers integration
-- 'NO-ACTION RI cascading from an after trigger

------------------------------------------------------------------
-- SET ENVIRONMENT
------------------------------------------------------------------


obey TEST_7_1_2(clean_up);
obey TEST_7_1_2(set_up);
log   LOG_7_1_2 clear;
obey TEST_7_1_2(tests);
LOG;
obey TEST_7_1_2(clean_up);
exit;

?section clean_up
DROP TRIGGER atrig712;
ALTER TABLE tab1B DROP CONSTRAINT ref_constr;

------------------------------------------------------------------
obey clearTables;

?section set_up
INSERT INTO tab1B VALUES (1,2);
INSERT INTO tab1B VALUES (2,3);
INSERT INTO tab1B VALUES (3,3);

ALTER TABLE tab1B ADD CONSTRAINT ref_constr 
	FOREIGN KEY (b) REFERENCES tab1B;  

---------------------------------
-- DEFINE TRIGGER atrig712
---------------------------------

CREATE TRIGGER atrig712
AFTER INSERT ON tab1B
REFERENCING NEW AS newR
FOR EACH ROW
UPDATE tab1B set b=b+1 
WHERE a <> newR.a;
?section tests

------------------------------------------------------------------
--          TEST CASE
------------------------------------------------------------------

INSERT INTO tab1B VALUES (4,3);

SELECT * FROM tab1B ORDER BY a; -- check result

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

INSERT INTO tab1B VALUES (6,4);

SELECT * FROM tab1B ORDER BY a; -- check result

------------------------------------------------------------------
--           END
------------------------------------------------------------------
