-- @@@ 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 @@@
-- semantics
-- using NULL in a WHEN clause


obey TEST_1_1_1_11(clean_up);
obey TEST_1_1_1_11(set_up);
log   LOG_1_1_1_11 clear;
obey TEST_1_1_1_11(tests);
LOG;
obey TEST_1_1_1_11(clean_up);
exit;

?section clean_up

drop trigger atrig;
obey clearTables;

?section set_up
SET SCHEMA cat1.schm;

insert into tab1a values (1 , NULL, 3,  4);
insert into tab1a values (2,   3, NULL, 5);
insert into tab1a values (3,   4,   5, NULL);

-----------------------------------
-- define atrig
-----------------------------------


?section tests

--------------------------------------------------------
-- TEST CASE
--------------------------------------------------------
CREATE TRIGGER atrig
AFTER UPDATE ON tab1A
REFERENCING OLD AS oldR, NEW AS newR FOR EACH ROW
WHEN (oldR.b IS NULL OR newR.d is NOT NULL)
Insert into tab1b values (newR.d, oldR.d);

update tab1a set d=b+c;
-- should fail due to the NOT NULL in tab1b

drop trigger atrig;

CREATE TRIGGER atrig
AFTER UPDATE ON tab1A
REFERENCING OLD AS oldR, NEW AS newR FOR EACH ROW
WHEN (oldR.b IS NULL OR newR.d is NOT NULL)
Insert into cat3.schm.tab3a values (newR.d, oldR.d);

update tab1a set d=b+c;

select * from tab1a order by a; -- check results
select * from cat3.schm.tab3a order by a; -- check results

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