/*

updateSite 



*/

CREATE OR REPLACE FUNCTION updateLandowner(
 	s_account       	integer,
	s_maf_ref		varchar(100),
	s_site_id		integer,
 	s_area      		integer, 
	s_landowner		integer,
	s_name                  varchar(100),             
 	s_description   	text ,                  
	s_address_1		varchar(100),
	s_address_2		varchar(100),
	s_latlng    		varchar(20),
	brood			int[][]
) RETURNS BOOLEAN AS $$
DECLARE
	brood_size	integer;
	-- site_maf_ref	integer;	
BEGIN
	brood_size      := array_upper( brood, 1 );
	-- site_maf_ref	:= s_maf_ref;
	-- first we insert into sites
	RAISE NOTICE 'about to start loop';
	FOR I IN 1..brood_size LOOP
		RAISE NOTICE 'about to update sitehives! site_id = %', s_site_id;
		UPDATE sitehives SET number = brood[I][2]::int where brood_type =  brood[I][1]::int and site = s_site_id;
		IF  NOT FOUND THEN
			RAISE EXCEPTION 'no update sitehives';
		END IF;

	END LOOP;
	RETURN TRUE;
 
	EXCEPTION
                WHEN RAISE_EXCEPTION or  STRING_DATA_LENGTH_MISMATCH or PLPGSQL_ERROR THEN
                RAISE NOTICE 'exception caught in stored function updateSite for name %', s_name;
                RETURN FALSE;

END;
$$ LANGUAGE plpgsql;

