--
-- apm__set_value/3
--
create or replace function apm__set_value(
  integer,
  character varying,
  character varying
) returns int4 as $$

declare
  set_value__package_id             alias for $1;  
  set_value__parameter_name         alias for $2;  
  set_value__attr_value             alias for $3;  
  v_parameter_id                    apm_parameter_values.parameter_id%TYPE;
  v_value_id                        apm_parameter_values.value_id%TYPE;
begin
    v_parameter_id := apm__id_for_name (set_value__package_id, set_value__parameter_name);

    -- Determine if the value exists
    select value_id into v_value_id from apm_parameter_values 
     where parameter_id = v_parameter_id 
     and package_id = set_value__package_id;
    update apm_parameter_values set attr_value = set_value__attr_value
     where value_id = v_value_id;
    update acs_objects set last_modified = now() 
     where object_id = v_value_id;
   --  exception 
     if NOT FOUND
       then
         v_value_id := apm_parameter_value__new(
            null,
            set_value__package_id,
            v_parameter_id,
            set_value__attr_value
         );
     end if;

    return 0; 
end;$$ language plpgsql;


--
-- apm__set_value/3
--
create or replace function apm__set_value(
  set_value__package_key character varying,
  set_value__parameter_name character varying,
  set_value__attr_value character varying
) returns int4 as $$

BEGIN
    return apm__set_global_value(set_value__package_key, set_value__parameter_name, set_value__attr_value);
END;    
$$ language plpgsql;