/*

addSite 



*/

CREATE OR REPLACE FUNCTION addSchedule(
 	s_account       	integer,
 	s_site      		integer, 
 	s_date      		varchar(100),
	s_inspectionType	integer,
 	s_info   		text                  
) RETURNS INTEGER AS $$
DECLARE
	scheduleID integer;
BEGIN
	-- first we insert into sites
	INSERT INTO SITESCHEDULE (id,account,site,date,type,additionalinfo)  VALUES (DEFAULT,s_account,s_site,to_date(s_date, 'DD-MM-YYYY') ,s_inspectionType,s_info) RETURNING id INTO scheduleID;
	IF FOUND THEN
		-- insert was successful
		RETURN scheduleID;
	ELSE
		RAISE EXCEPTION 'insert failed on site schedule';
	END IF;
	EXCEPTION
                WHEN RAISE_EXCEPTION or  STRING_DATA_LENGTH_MISMATCH or PLPGSQL_ERROR THEN
                RAISE NOTICE 'exception caught in stored function addStte for name %', name;
                RETURN FALSE;

END;
$$ LANGUAGE plpgsql;

