-- @@@ 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 @@@
-- HL_R2_Triggers_Spec.doc: SPJ enhancements to Triggers
-- CS with one or more SET statements
-- Result: Error

obey TEST_SPJC_CSTA_003(clean_up);
obey TEST_SPJC_CSTA_003(set_up);
log  LOG_SPJC_CSTA_003 clear;
obey TEST_SPJC_CSTA_003(tests);
LOG;
obey TEST_SPJC_CSTA_003(clean_up);
exit;

?section clean_up
set schema CAT1.SCHM;


drop trigger TRIG01_SPJC_CSTA_003;
drop trigger TRIG02_SPJC_CSTA_003;

drop table TAB01_SPJC_CSTA_003;
drop table TAB02_SPJC_CSTA_003;

?section set_up
set schema CAT1.SCHM;

SET ENVVAR ALLOW_CS_IN_SQLCI 1;
CONTROL QUERY DEFAULT POS 'OFF';

create table TAB01_SPJC_CSTA_003(a int, b int, c int, d int);
create table TAB02_SPJC_CSTA_003(a int, b int, c int, d int);

insert into TAB01_SPJC_CSTA_003 values(1, 2, 3, 4);

insert into TAB02_SPJC_CSTA_003 values(1, 2, 3, 4);

?section tests

------------------------------------------------------------------
-- TEST CASE 01: CS with one or more SET statements (row trigger)
-- Result: ERROR[11014] A BEFORE trigger allows only SIGNAL and SET
-- operations.
------------------------------------------------------------------

CREATE TRIGGER TRIG01_SPJC_CSTA_003 BEFORE UPDATE ON
TAB01_SPJC_CSTA_003
REFERENCING OLD ROW AS O, NEW ROW AS N
FOR EACH ROW
	INSERT INTO TAB02_SPJC_CSTA_003 VALUES(N.A, N.B, N.C, N.D);
------------------------------------------------------------------

------------------------------------------------------------------
-- TEST CASE 02: CS with one or more SET statements (statement trigger)
-- Result: ERROR[11010] A BEFORE trigger works only at row granularity.
------------------------------------------------------------------

CREATE TRIGGER TRIG02_SPJC_CSTA_003 BEFORE UPDATE ON
TAB01_SPJC_CSTA_003
FOR EACH STATEMENT
	INSERT INTO TAB02_SPJC_CSTA_003 values(11, 22, 33, 44);
------------------------------------------------------------------
