Skip to content
Snippets Groups Projects
Commit b340fac5 authored by Ruud Overeem's avatar Ruud Overeem
Browse files

Task #8531: Nieuw function for the TreeStatusEvent daemon.

parent cec90f41
No related branches found
No related tags found
No related merge requests found
...@@ -4807,6 +4807,7 @@ SAS/OTDB/sql/getDefaultTemplates_func.sql -text ...@@ -4807,6 +4807,7 @@ SAS/OTDB/sql/getDefaultTemplates_func.sql -text
SAS/OTDB/sql/getModifiedTrees_func.sql -text SAS/OTDB/sql/getModifiedTrees_func.sql -text
SAS/OTDB/sql/getMomID2treeID_func.sql -text SAS/OTDB/sql/getMomID2treeID_func.sql -text
SAS/OTDB/sql/getSchedulerInfo_func.sql -text SAS/OTDB/sql/getSchedulerInfo_func.sql -text
SAS/OTDB/sql/getStateChanges_func.sql -text
SAS/OTDB/sql/getTreeGroup_func.sql -text SAS/OTDB/sql/getTreeGroup_func.sql -text
SAS/OTDB/sql/getTreesInPeriod_func.sql -text SAS/OTDB/sql/getTreesInPeriod_func.sql -text
SAS/OTDB/sql/getVTitem_func.sql -text SAS/OTDB/sql/getVTitem_func.sql -text
......
...@@ -37,6 +37,7 @@ DROP SEQUENCE IF EXISTS OTDBtreeID; ...@@ -37,6 +37,7 @@ DROP SEQUENCE IF EXISTS OTDBtreeID;
DROP SEQUENCE IF EXISTS OTDBgroupID; DROP SEQUENCE IF EXISTS OTDBgroupID;
DROP TABLE IF EXISTS StateHistory CASCADE; DROP TABLE IF EXISTS StateHistory CASCADE;
DROP INDEX IF EXISTS otdbtree_treeid_indx; DROP INDEX IF EXISTS otdbtree_treeid_indx;
DROP INDEX IF EXISTS statehist_creation_idx;
CREATE SEQUENCE OTDBtreeID START 1; CREATE SEQUENCE OTDBtreeID START 1;
-- Create a new start number based on current time. To prevent overlap in treeid's -- Create a new start number based on current time. To prevent overlap in treeid's
...@@ -98,6 +99,9 @@ CREATE TABLE StateHistory ( ...@@ -98,6 +99,9 @@ CREATE TABLE StateHistory (
momID INT4 NOT NULL, momID INT4 NOT NULL,
state INT2 NOT NULL, state INT2 NOT NULL,
userID INT4 NOT NULL REFERENCES operator(ID), userID INT4 NOT NULL REFERENCES operator(ID),
timestamp TIMESTAMP(0) DEFAULT now() timestamp TIMESTAMP(0) DEFAULT now(),
creation TIMESTAMP(6) DEFAULT now()
) WITHOUT OIDS; ) WITHOUT OIDS;
CREATE INDEX statehist_creation_idx ON statehistory(creation);
--
-- getStateChanges.sql: function for getting state changes in a given period
--
-- Copyright (C) 2015
-- ASTRON (Netherlands Foundation for Research in Astronomy)
-- P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, softwaresupport@astron.nl
--
-- This program 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 2 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 this program; if not, write to the Free Software
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
--
-- $Id: getStateList_func.sql 30919 2015-02-05 15:26:22Z amesfoort $
--
--
-- getStateChanges(begindate, enddate)
--
-- Get a list of statechanges.
--
-- Authorisation: none
--
-- Tables: otdbtree read
-- otdbuser read
--
-- Types: treeState
--
DROP TYPE IF EXISTS stateChange CASCADE;
CREATE TYPE stateChange AS (
-- $Id: create_types.sql 30919 2015-02-05 15:26:22Z amesfoort $
treeID INT4, -- OTDBtree.treeID%TYPE,
momID INT4, -- OTDBtree.momID%TYPE,
state INT2, -- treestate.ID%TYPE,
username VARCHAR(20), -- OTDBuser.username%TYPE,
modtime timestamp(0),
creation timestamp(6)
);
CREATE OR REPLACE FUNCTION getStateChanges(TIMESTAMP(6), TIMESTAMP(6))
RETURNS SETOF stateChange AS '
-- $Id: getStateList_func.sql 30919 2015-02-05 15:26:22Z amesfoort $
DECLARE
vRecord RECORD;
vQuery TEXT;
vKeyField TEXT;
BEGIN
-- create query for treeID (when filled)
vQuery := \'WHERE \';
IF $1 IS NOT NULL THEN
IF $2 IS NULL THEN
vQuery := vQuery || \'s.creation >\' || chr(39) || $1 || chr(39);
ELSE
vQuery := vQuery || \'s.creation >\' || chr(39) || $1 || chr(39)
|| \' AND s.creation <=\' || chr(39) || $2 || chr(39);
END IF;
END IF;
-- do selection
FOR vRecord IN EXECUTE \'
SELECT s.treeID,
s.momID,
s.state,
u.username,
s.timestamp,
s.creation
FROM StateHistory s
INNER JOIN OTDBuser u ON s.userid = u.userid
\' || vQuery || \'
ORDER BY s.creation ASC\'
LOOP
RETURN NEXT vRecord;
END LOOP;
RETURN;
END
' LANGUAGE plpgsql;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment