-- @@@ 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 @@@
-- Modify test for triggers
-- This case tests if when adding a new partition the trigger
-- info is copied to the new partition's resource fork
-- Case : 10-040603-3876 

obey TEST_9_1_1(clean_up);
LOG  LOG_9_1_1;
obey TEST_9_1_1(set_up);
obey TEST_9_1_1(tests);
LOG;
obey TEST_9_1_1(clean_up);
exit;



?section clean_up
set schema cat1.schm;
drop trigger trig10;
drop table t10;



?section set_up
set schema cat1.schm;
create table t10
   (a int not null, 
    b int, 
    primary key (a) not droppable)
   LOCATION $$partition$$
   RANGE PARTITION (ADD FIRST KEY 2000 LOCATION $$partition2$$);


insert into t10 values (1,1), (1000,1000), (2000,2000), (3000,3000);

create trigger trig10
before delete on t10
for each row
SIGNAL sqlstate 'S0000'('delete') ;



?section tests
set schema cat1.schm;

delete from t10;

-- MODIFY adds a new second partition and should copy be triggers info
-- to the Resource fork of the second partitiona, this is verified in
-- the last delete
modify table t10 add partition where first key  upto value(
        4000) to location $$partition1$$;

delete from t10;

-- Since this Modify deletes the first partition after moving the rows
-- to the second partition, the second partition now becomes the primary
-- which was added by the before MODIFY statement.
modify table t10 move partition where first partition to next partition;

-- This should fail as there is delete trigger on the table. If the trigger
-- info was not copied correctly when doing the FIRST MODIFY then we will 
-- see a an assertion which means case 10-040603-3876 is broke.
delete from t10;

select * from t10;

