/*

getSiteInspections



*/

CREATE OR REPLACE FUNCTION getSiteInSpections(
        s_account               integer
) RETURNS  SETOF RECORD AS  $$
DECLARE
inspections RECORD; 
BEGIN
        -- open cursor 
	FOR  inspections IN SELECT ins.id as id, s.name as site, ins.insp_date as date,ins.health as health, ins.type as type, ins.afb as afbcheck, pest.description as pestcontrol, ins.photo_path as photo from siteinspections ins, sites s, pestcontrol pest where s.id=ins.site and pest.id= ins.pestcontrol and  ins.account = s_account LOOP
	RETURN NEXT inspections;
        END LOOP; 
	RETURN;                                                    
        EXCEPTION
                WHEN RAISE_EXCEPTION or  STRING_DATA_LENGTH_MISMATCH or PLPGSQL_ERROR THEN
                RAISE NOTICE 'exception caught in stored function addStte for name %', name;

END;
$$ LANGUAGE plpgsql;

