--
-- TestSelfModify.txt
--

-- TestSelfModify.txt is used by TestSelf.java to test the database
--
-- This is the second part of a three part suite of scripts to test persistence in the same DB
--
-- Comment lines must start with -- and are ignored
-- Lines starting with spaces belongs to last line
-- Checked lines start with comments containing <tag> where <tag> is:
--   c <rows>     ResultSet expects a with <row> columns
--   r <string>   ResultSet expected with <string> result in first row/column
--   u <count>    Update count <count> expected
--   e            Exception must occur
--
--bug #824031 continued
--scripting test for order of indexes
/*c1*/SELECT * FROM APP WHERE VARIANT_ID = 51;
/*c1*/SELECT * FROM APP WHERE APP_NAME = 'Eran';
/*c1*/SELECT * FROM APP WHERE APP_NAME = 'Shelly';
/*c2*/SELECT * FROM APP;
--
-- TEST 1
-- Correct handling of index creation for foreign keys
-- insert some values
/*u1*/insert into verein values ('abcdefg');
/*u1*/insert into verein values ('hijklmn');
/*u1*/insert into verein values ('opqrstu');
/*u1*/insert into verein values ('vwxyz');
/*u1*/insert into bewerb values ('abcdefg',1);
/*e*/insert into bewerb values ('abcdefg',2);
/*u1*/insert into bewerb values ('hijklmn',5);
/*e*/insert into bewerb values ('hijklmn',6);
/*u1*/insert into bewerb values ('opqrstu',8);
/*e*/insert into bewerb values ('opqrstu',9);
/*u1*/insert into bewerb values ('vwxyz',10);

--CHECKPOINT DEFRAG

--test identity increment
INSERT INTO APP2 (VALUE) VALUES(11);
INSERT INTO APP2 (VALUE) VALUES(12);

/*r3,12*/ SELECT COUNT(ID), MAX(VALUE) FROM APP2
/*r3,10*/ SELECT COUNT(ID), MIN(VALUE) FROM APP2

--test result of update before previous shutdown
/*r
  14,newdir,NULL,NULL,NULL
*/select * from file;

--test insert into table

CREATE TABLE NEWAPP AS (SELECT * FROM APP) WITH DATA;
/*c1*/SELECT * FROM NEWAPP WHERE APP_NAME = 'Eran';
/*c1*/SELECT * FROM NEWAPP WHERE APP_NAME = 'Shelly';
/*c2*/SELECT * FROM NEWAPP;

INSERT INTO NEWAPP (SELECT * FROM APP)
/*c2*/SELECT * FROM NEWAPP WHERE APP_NAME = 'Eran';
/*c2*/SELECT * FROM NEWAPP WHERE APP_NAME = 'Shelly';
/*c4*/SELECT * FROM NEWAPP;

--test separate identity and primary key

/*e*/insert into tident values (10, default);
/*r
 10,0
 11,1
 12,2
*/select * from tident
insert into tident values (9, default);
-- SHUTDOWN is necessary for test1
/*u0*/SHUTDOWN;

