-- Copyright (C) 2012 The Meme Factory, Inc., http://www.meme.com/
--
-- This file is part of Gombe-MI.
--
-- Gombe-MI is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with Gombe-MI. If not, see .
--
-- SQL to test the biography view.
--
-- All data appearing in this work are fictitious. Any resemblance to
-- actual data, living or archived, is purely coincidental.
--
-- Karl O. Pinc
--
-- Bugs:
-- The regression test system does not like it that timestamps change.
-- Ignore the problem by not displaying the import_datetime column.
--
-- Main tables.
--
select 'Test insert with no twins.';
-- biography
insert into biography (
animid
, animname
, birthgroup
, bgcertainty
, sex
, momid
, firstborn
, birthdate
, bdmin
, bdmax
, bddist
, entrydate
, entrytype
, departdate
, departdateerror
, departtype)
values (
'MOM'
, 'Some mother'
, 'U'
, 'C'
, 'F'
, NULL
, 'U'
, '1955-01-01'
, '1955-01-01'
, '1955-01-01'
, 'R'
, '1960-01-01'
, 'B'
, '1995-01-01'
, 0
, 'D')
,( 'KID'
, 'Some offspring'
, 'K'
, 'C'
, 'M'
, 'MOM'
, 'Y'
, '1965-01-01'
, '1965-01-01'
, '1965-01-01'
, 'R'
, '1965-01-01'
, 'B'
, '2010-01-01'
, 0
, 'D')
,( 'DAD'
, 'Some dad'
, 'M'
, 'C'
, 'M'
, NULL
, 'U'
, '1954-01-01'
, '1954-01-01'
, '1954-01-01'
, 'R'
, '1960-01-01'
, 'B'
, '2005-01-01'
, 0
, 'D')
,( 'MGE'
, 'Dummy variable - stranger'
, NULL
, NULL
, 'F'
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL);
select animid
, animname
, birthgroup
, bgcertainty
, sex
, momid
, firstborn
, birthdate
, bdmin
, bdmax
, bddist
, entrydate
, entrytype
, departdate
, departdateerror
, departtype
from biography_data order by animid;
select * from twins order by animid;
-- Test insert with twins.
select 'Test insert with twins.';
-- biography
insert into biography (
animid
, animname
, birthgroup
, bgcertainty
, sex
, momid
, firstborn
, birthdate
, bdmin
, bdmax
, bddist
, entrydate
, entrytype
, departdate
, departdateerror
, departtype
, twin)
values
( 'T1'
, 'Some twin'
, 'K'
, 'C'
, 'M'
, 'MOM'
, 'Y'
, '1972-01-01'
, '1972-01-01'
, '1972-01-01'
, 'R'
, '1972-01-01'
, 'B'
, '2010-01-01'
, 0
, 'D'
, 'T2')
,( 'T2'
, 'Some other twin'
, 'K'
, 'C'
, 'M'
, 'MOM'
, 'Y'
, '1972-01-01'
, '1972-01-01'
, '1972-01-01'
, 'R'
, '1972-01-01'
, 'B'
, '2010-01-01'
, 0
, 'D'
, 'T1');
select animid
, animname
, birthgroup
, bgcertainty
, sex
, momid
, firstborn
, birthdate
, bdmin
, bdmax
, bddist
, entrydate
, entrytype
, departdate
, departdateerror
, departtype
from biography_data order by animid;
select 'Should have twins on TWINS.';
select * from twins order by animid;
-- Test selection.
select 'selecting the biography view';
select animid
, animname
, birthgroup
, bgcertainty
, sex
, momid
, firstborn
, birthdate
, bdmin
, bdmax
, bddist
, entrydate
, entrytype
, departdate
, departdateerror
, departtype
, twin
from biography order by animid;
-- Try updating biography.
-- Get rid of twins.
select 'Test update to delete twins.';
update biography
set twin = NULL
where animid = 'T1' or animid = 'T2';
select 'No twins should be left on TWINS.';
select animid
, animname
, birthgroup
, bgcertainty
, sex
, momid
, firstborn
, birthdate
, bdmin
, bdmax
, bddist
, entrydate
, entrytype
, departdate
, departdateerror
, departtype
from biography_data order by animid;
select * from twins order by animid;
-- Update biography.
-- Add twins back.
select 'Test update to add twins back.';
begin;
update biography
set twin = 'T2'
where animid = 'T1';
update biography
set twin = 'T1'
where animid = 'T2';
commit;
select 'The twins should be back on TWINS.';
select animid
, animname
, birthgroup
, bgcertainty
, sex
, momid
, firstborn
, birthdate
, bdmin
, bdmax
, bddist
, entrydate
, entrytype
, departdate
, departdateerror
, departtype
from biography_data order by animid;
select * from twins order by animid;
--
-- Delete from biography.
--
select 'Test delete of biography';
delete
from biography
where animid = 'T1' or animid = 'T2';
select 'No twins should be left, anywhere.';
select animid
, animname
, birthgroup
, bgcertainty
, sex
, momid
, firstborn
, birthdate
, bdmin
, bdmax
, bddist
, entrydate
, entrytype
, departdate
, departdateerror
, departtype
from biography_data order by animid;
select * from twins order by animid;