Forum OpenACS Development: XQL Problem in loading package

Collapse
Posted by Sid Widge on
Hi, I have been trying for a while to fix apermission problem, I just wanted to know that whether you would port the code for a loop in xql file same as we did for the .sql files. I am not sure of this, here is my code for the .xql file see if anyone can advice me on how to go from here.
create function inline_0 ()
returns integer as'
        declare 
          add_a record;
          add_b record;
          add_c record;
       begin 
         if :role = 'read' then
            for add_a in select member_id
              from group_member_map
              where group_id = :group_id;
            loop
                acs_permission__grant_permission(:pres_item_id,
c__member_id,
'wp_view_presentation');
            end loop;
        else if (:role = 'write') then
            for add_b in select member_id
              from group_member_map
              where group_id = :group_id;
              loop
                acs_permission__grant_permission(:pres_item_id,
c__member_id, 
'wp_view_presentation');
                acs_permission__grant_permission(:pres_item_id,
c__member_id,
'wp_edit_presentation');
            end loop;
        else
            for add_c in select member_id
              from group_member_map
              where group_id = :group_id;
             loop
                acs_permission__grant_permission(:pres_item_id,
c__member_id,
'wp_view_presentation');
                acs_permission__grant_permission(:pres_item_id,
c__member_id,
'wp_edit_presentation');
                acs_permission__grant_permission(:pres_item_id,
c__member_id,
'wp_admin_presentation');
            end loop;
        end if;

end;' langauge 'plpgsql';
select inline_0 ();
drop function inline_0 ();
Collapse
Posted by Don Baccus on
The PG db_exec_pgsql routine will bury your code in an inline for you, much as you've done explicitly, so you've got the right idea but actually it's probably best to let the db api routine do it.

Eventually, I'd like to see code like this migrate into PL/[pg]SQL funcs/procs anyway.  Not only won't one have to kludge around such inlines for PG and other RDBMS's that don't support inline programmatic code blocks, the code will only have to be compiled once.