Index: openacs-4/packages/acs-content-repository/sql/postgresql/content-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/sql/postgresql/content-create.sql,v diff -u -r1.57 -r1.58 --- openacs-4/packages/acs-content-repository/sql/postgresql/content-create.sql 20 Feb 2011 00:34:00 -0000 1.57 +++ openacs-4/packages/acs-content-repository/sql/postgresql/content-create.sql 7 Jul 2011 10:46:02 -0000 1.58 @@ -238,19 +238,36 @@ foreign key (item_id) references cr_items(item_id); -create function cr_items_get_tree_sortkey(integer) returns varbit as ' -declare - p_item_id alias for $1; -begin + + +-- added +select define_function_args('cr_items_get_tree_sortkey','item_id'); + +-- +-- procedure cr_items_get_tree_sortkey/1 +-- +CREATE OR REPLACE FUNCTION cr_items_get_tree_sortkey( + p_item_id integer +) RETURNS varbit AS $$ +DECLARE +BEGIN return tree_sortkey from cr_items where item_id = p_item_id; -end;' language 'plpgsql' stable strict; +END; +$$ LANGUAGE plpgsql stable strict; -create function cr_items_tree_insert_tr () returns opaque as ' -declare + + +-- +-- procedure cr_items_tree_insert_tr/0 +-- +CREATE OR REPLACE FUNCTION cr_items_tree_insert_tr( + +) RETURNS trigger AS $$ +DECLARE v_parent_sk varbit default null; v_max_child_sortkey varbit; v_parent_id integer default null; -begin +BEGIN select item_id into v_parent_id from cr_items @@ -281,19 +298,27 @@ end if; return new; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; create trigger cr_items_tree_insert_tr before insert on cr_items for each row execute procedure cr_items_tree_insert_tr (); -create function cr_items_tree_update_tr () returns opaque as ' -declare + + +-- +-- procedure cr_items_tree_update_tr/0 +-- +CREATE OR REPLACE FUNCTION cr_items_tree_update_tr( + +) RETURNS trigger AS $$ +DECLARE v_parent_sk varbit default null; v_max_child_sortkey varbit; v_parent_id integer default null; v_old_parent_length integer; -begin +BEGIN if new.item_id = old.item_id and ((new.parent_id = old.parent_id) or (new.parent_id is null and old.parent_id is null)) then @@ -335,7 +360,8 @@ return new; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; create trigger cr_items_tree_update_tr after update on cr_items @@ -487,20 +513,27 @@ -- foreign key (latest_revision) references cr_revisions(revision_id); -create function cr_revision_del_ri_trg() returns opaque as ' -declare + + +-- +-- procedure cr_revision_del_ri_tr/0 +-- +CREATE OR REPLACE FUNCTION cr_revision_del_ri_tr( + +) RETURNS trigger AS $$ +DECLARE dummy integer; v_latest integer; v_live integer; -begin +BEGIN select 1 into dummy from cr_revisions where revision_id = old.live_revision; if FOUND then - raise EXCEPTION ''Referential Integrity: live_revision still exists: %'', old.live_revision; + raise EXCEPTION 'Referential Integrity: live_revision still exists: %', old.live_revision; end if; select 1 into dummy @@ -510,26 +543,34 @@ revision_id = old.latest_revision; if FOUND then - raise EXCEPTION ''Referential Integrity: latest_revision still exists: %'', old.latest_revision; + raise EXCEPTION 'Referential Integrity: latest_revision still exists: %', old.latest_revision; end if; return old; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create function cr_revision_ins_ri_trg() returns opaque as ' -declare + + +-- +-- procedure cr_revision_ins_ri_tr/0 +-- +CREATE OR REPLACE FUNCTION cr_revision_ins_ri_tr( + +) RETURNS trigger AS $$ +DECLARE dummy integer; v_latest integer; v_live integer; -begin +BEGIN select 1 into dummy from cr_revisions where revision_id = new.live_revision; if NOT FOUND and new.live_revision is NOT NULL then - raise EXCEPTION ''Referential Integrity: live_revision does not exist: %'', new.live_revision; + raise EXCEPTION 'Referential Integrity: live_revision does not exist: %', new.live_revision; end if; select 1 into dummy @@ -539,26 +580,34 @@ revision_id = new.latest_revision; if NOT FOUND and new.latest_revision is NOT NULL then - raise EXCEPTION ''Referential Integrity: latest_revision does not exist: %'', new.latest_revision; + raise EXCEPTION 'Referential Integrity: latest_revision does not exist: %', new.latest_revision; end if; return new; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create function cr_revision_up_ri_trg() returns opaque as ' -declare + + +-- +-- procedure cr_revision_up_ri_tr/0 +-- +CREATE OR REPLACE FUNCTION cr_revision_up_ri_tr( + +) RETURNS trigger AS $$ +DECLARE dummy integer; v_latest integer; v_live integer; -begin +BEGIN select 1 into dummy from cr_revisions where revision_id = new.live_revision; if NOT FOUND and new.live_revision <> old.live_revision and new.live_revision is NOT NULL then - raise EXCEPTION ''Referential Integrity: live_revision does not exist: %'', new.live_revision; + raise EXCEPTION 'Referential Integrity: live_revision does not exist: %', new.live_revision; end if; select 1 into dummy @@ -568,16 +617,24 @@ revision_id = new.latest_revision; if NOT FOUND and new.latest_revision <> old.latest_revision and new.latest_revision is NOT NULL then - raise EXCEPTION ''Referential Integrity: latest_revision does not exist: %'', new.latest_revision; + raise EXCEPTION 'Referential Integrity: latest_revision does not exist: %', new.latest_revision; end if; return new; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create function cr_revision_del_rev_ri_trg() returns opaque as ' -declare + + +-- +-- procedure cr_revision_del_rev_ri_tr/0 +-- +CREATE OR REPLACE FUNCTION cr_revision_del_rev_ri_tr( + +) RETURNS trigger AS $$ +DECLARE dummy integer; -begin +BEGIN select 1 into dummy from cr_items @@ -587,7 +644,7 @@ live_revision = old.revision_id; if FOUND then - raise EXCEPTION ''Referential Integrity: attempting to delete live_revision: %'', old.revision_id; + raise EXCEPTION 'Referential Integrity: attempting to delete live_revision: %', old.revision_id; end if; select 1 into dummy @@ -599,51 +656,60 @@ latest_revision = old.revision_id; if FOUND then - raise EXCEPTION ''Referential Integrity: attempting to delete latest_revision: %'', old.revision_id; + raise EXCEPTION 'Referential Integrity: attempting to delete latest_revision: %', old.revision_id; end if; return old; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- reimplementation of RI triggers. (DanW dcwickstrom@earthlink.net) -create trigger cr_revision_del_ri_trg +create trigger cr_revision_del_ri_tr after delete on cr_items -for each row execute procedure cr_revision_del_ri_trg(); +for each row execute procedure cr_revision_del_ri_tr(); -create trigger cr_revision_up_ri_trg +create trigger cr_revision_up_ri_tr after update on cr_items -for each row execute procedure cr_revision_up_ri_trg(); +for each row execute procedure cr_revision_up_ri_tr(); -create trigger cr_revision_ins_ri_trg +create trigger cr_revision_ins_ri_tr after insert on cr_items -for each row execute procedure cr_revision_ins_ri_trg(); +for each row execute procedure cr_revision_ins_ri_tr(); -create trigger cr_revision_del_rev_ri_trg +create trigger cr_revision_del_rev_ri_tr after delete on cr_revisions -for each row execute procedure cr_revision_del_rev_ri_trg(); +for each row execute procedure cr_revision_del_rev_ri_tr(); -- (DanW - OpenACS) Added cleanup trigger to log file items that need -- to be cleaned up from the CR. -create function cr_cleanup_cr_files_del_trg() returns opaque as ' -declare + + +-- +-- procedure cr_cleanup_cr_files_del_tr/0 +-- +CREATE OR REPLACE FUNCTION cr_cleanup_cr_files_del_tr( + +) RETURNS trigger AS $$ +DECLARE -begin +BEGIN insert into cr_files_to_delete select r.content as path, i.storage_area_key from cr_items i, cr_revisions r where i.item_id = r.item_id and r.revision_id = old.revision_id - and i.storage_type = ''file''; + and i.storage_type = 'file'; return old; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create trigger cr_cleanup_cr_files_del_trg +create trigger cr_cleanup_cr_files_del_tr before delete on cr_revisions -for each row execute procedure cr_cleanup_cr_files_del_trg(); +for each row execute procedure cr_cleanup_cr_files_del_tr(); create table cr_revision_attributes ( @@ -946,18 +1012,35 @@ -- RI Indexes create index cr_keywords_parent_id_idx ON cr_keywords(parent_id); -create function cr_keywords_get_tree_sortkey(integer) returns varbit as ' -declare - p_keyword_id alias for $1; -begin + + +-- added +select define_function_args('cr_keywords_get_tree_sortkey','keyword_id'); + +-- +-- procedure cr_keywords_get_tree_sortkey/1 +-- +CREATE OR REPLACE FUNCTION cr_keywords_get_tree_sortkey( + p_keyword_id integer +) RETURNS varbit AS $$ +DECLARE +BEGIN return tree_sortkey from cr_keywords where keyword_id = p_keyword_id; -end;' language 'plpgsql' stable strict; +END; +$$ LANGUAGE plpgsql stable strict; -create function cr_keywords_tree_insert_tr () returns opaque as ' -declare + + +-- +-- procedure cr_keywords_tree_insert_tr/0 +-- +CREATE OR REPLACE FUNCTION cr_keywords_tree_insert_tr( + +) RETURNS trigger AS $$ +DECLARE v_parent_sk varbit default null; v_max_value integer; -begin +BEGIN if new.parent_id is null then select max(tree_leaf_key_to_int(tree_sortkey)) into v_max_value from cr_keywords @@ -976,20 +1059,28 @@ return new; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; create trigger cr_keywords_tree_insert_tr before insert on cr_keywords for each row execute procedure cr_keywords_tree_insert_tr (); -create function cr_keywords_tree_update_tr () returns opaque as ' -declare + + +-- +-- procedure cr_keywords_tree_update_tr/0 +-- +CREATE OR REPLACE FUNCTION cr_keywords_tree_update_tr( + +) RETURNS trigger AS $$ +DECLARE v_parent_sk varbit default null; v_max_value integer; p_id integer; v_rec record; - clr_keys_p boolean default ''t''; -begin + clr_keys_p boolean default 't'; +BEGIN if new.keyword_id = old.keyword_id and ((new.parent_id = old.parent_id) or (new.parent_id is null and old.parent_id is null)) @@ -1007,7 +1098,7 @@ if clr_keys_p then update cr_keywords set tree_sortkey = null where tree_sortkey between new.tree_sortkey and tree_right(new.tree_sortkey); - clr_keys_p := ''f''; + clr_keys_p := 'f'; end if; select parent_id into p_id @@ -1036,7 +1127,8 @@ return new; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; create trigger cr_keywords_tree_update_tr after update on cr_keywords @@ -1093,14 +1185,15 @@ insert into cr_text values (NULL); -create function cr_text_tr () returns opaque as ' -begin +CREATE OR REPLACE FUNCTION cr_text_tr () RETURNS trigger AS $$ +BEGIN - raise EXCEPTION ''-20000: Inserts are not allowed into cr_text.''; + raise EXCEPTION '-20000: Inserts are not allowed into cr_text.'; return new; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; create trigger cr_text_tr before insert on cr_text for each row execute procedure cr_text_tr (); @@ -1161,23 +1254,29 @@ -- by default, map all MIME types to 'content_revision' -create function inline_1 () -returns integer as ' -declare + + +-- +-- procedure inline_1/0 +-- +CREATE OR REPLACE FUNCTION inline_1( + +) RETURNS integer AS $$ +DECLARE v_id integer; -begin +BEGIN - PERFORM content_type__register_mime_type(''content_revision'', - ''text/html''); - PERFORM content_type__register_mime_type(''content_revision'', - ''text/plain''); - PERFORM content_type__register_mime_type(''content_revision'', - ''application/rtf''); + PERFORM content_type__register_mime_type('content_revision', + 'text/html'); + PERFORM content_type__register_mime_type('content_revision', + 'text/plain'); + PERFORM content_type__register_mime_type('content_revision', + 'application/rtf'); v_id := content_folder__new ( - ''pages'', - ''Pages'', - ''Site pages go here'', + 'pages', + 'Pages', + 'Site pages go here', -4, null, content_item__get_root_folder(null), @@ -1188,31 +1287,31 @@ PERFORM content_folder__register_content_type( v_id, - ''content_revision'', - ''t'' + 'content_revision', + 't' ); PERFORM content_folder__register_content_type( v_id, - ''content_folder'', - ''t'' + 'content_folder', + 't' ); PERFORM content_folder__register_content_type( v_id, - ''content_symlink'', - ''t'' + 'content_symlink', + 't' ); -- add the root content folder to acs_magic_objects insert into acs_magic_objects (name, object_id) - select ''cr_item_root'', + select 'cr_item_root', content_item__get_root_folder(null); v_id := content_folder__new ( - ''templates'', - ''Templates'', - ''Templates which render the pages go here'', + 'templates', + 'Templates', + 'Templates which render the pages go here', -4, null, content_template__get_root_folder(), @@ -1223,60 +1322,67 @@ PERFORM content_folder__register_content_type( v_id, - ''content_folder'', - ''t'' + 'content_folder', + 't' ); PERFORM content_folder__register_content_type( v_id, - ''content_symlink'', - ''t'' + 'content_symlink', + 't' ); PERFORM content_folder__register_content_type( v_id, - ''content_template'', - ''t'' + 'content_template', + 't' ); -- add to acs_magic_objects insert into acs_magic_objects (name, object_id) - select ''cr_template_root'', + select 'cr_template_root', content_template__get_root_folder(); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select inline_1 (); drop function inline_1 (); -create function inline_2 () -returns integer as ' -declare + + +-- +-- procedure inline_2/0 +-- +CREATE OR REPLACE FUNCTION inline_2( + +) RETURNS integer AS $$ +DECLARE v_item_id integer; v_revision_id integer; -begin +BEGIN - select nextval(''t_acs_object_id_seq'') into v_item_id; + select nextval('t_acs_object_id_seq') into v_item_id; PERFORM content_template__new( - ''default_template'', - ''-200'', + 'default_template', + '-200', v_item_id, now(), null, null ); v_revision_id := content_revision__new( - ''Template'', + 'Template', NULL, now(), - ''text/html'', + 'text/html', null, - ''@text;noquote@'', + '@text;noquote@', v_item_id, NULL, now(), @@ -1299,27 +1405,28 @@ PERFORM content_type__register_template( - ''content_revision'', + 'content_revision', v_item_id, - ''public'', - ''t''); + 'public', + 't'); PERFORM content_type__register_template( - ''image'', + 'image', v_item_id, - ''public'', - ''t''); + 'public', + 't'); -- testing, this may go away. DanW PERFORM content_type__register_template( - ''content_template'', + 'content_template', v_item_id, - ''public'', - ''t''); + 'public', + 't'); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select inline_2 (); Index: openacs-4/packages/acs-content-repository/sql/postgresql/content-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/sql/postgresql/content-drop.sql,v diff -u -r1.5 -r1.6 --- openacs-4/packages/acs-content-repository/sql/postgresql/content-drop.sql 11 Apr 2011 01:08:27 -0000 1.5 +++ openacs-4/packages/acs-content-repository/sql/postgresql/content-drop.sql 7 Jul 2011 10:46:02 -0000 1.6 @@ -13,30 +13,37 @@ -- set serveroutput on -- unregistering types, deleting the default folders -create function inline_0 () returns integer as ' -declare + + +-- +-- procedure inline_0/0 +-- +CREATE OR REPLACE FUNCTION inline_0( + +) RETURNS integer AS $$ +DECLARE v_id integer; -begin +BEGIN -- root folder for templates v_id := content_template__get_root_folder(); PERFORM content_folder__unregister_content_type( v_id, - ''content_template'', - ''t'' + 'content_template', + 't' ); PERFORM content_folder__unregister_content_type( v_id, - ''content_symlink'', - ''t'' + 'content_symlink', + 't' ); PERFORM content_folder__unregister_content_type( v_id, - ''content_folder'', - ''t'' + 'content_folder', + 't' ); PERFORM content_folder__delete(v_id); @@ -47,27 +54,28 @@ PERFORM content_folder__unregister_content_type( v_id, - ''content_symlink'', - ''t'' + 'content_symlink', + 't' ); PERFORM content_folder__unregister_content_type( v_id, - ''content_folder'', - ''t'' + 'content_folder', + 't' ); PERFORM content_folder__unregister_content_type ( v_id, - ''content_revision'', - ''t'' + 'content_revision', + 't' ); PERFORM content_folder__delete (v_id); return null; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select inline_0 (); Index: openacs-4/packages/acs-content-repository/sql/postgresql/content-extlink.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/sql/postgresql/content-extlink.sql,v diff -u -r1.20 -r1.21 --- openacs-4/packages/acs-content-repository/sql/postgresql/content-extlink.sql 10 Feb 2009 18:31:54 -0000 1.20 +++ openacs-4/packages/acs-content-repository/sql/postgresql/content-extlink.sql 7 Jul 2011 10:46:02 -0000 1.21 @@ -10,26 +10,36 @@ -- License. Full text of the license is available from the GNU Project: -- http://www.fsf.org/copyleft/gpl.html -select define_function_args('content_extlink__new','name,url,label,description,parent_id,extlink_id,creation_date;now,creation_user,creation_ip,package_id'); -create or replace function content_extlink__new (varchar,varchar,varchar,varchar,integer,integer,timestamptz,integer,varchar,integer) -returns integer as ' -declare - new__name alias for $1; -- default null - new__url alias for $2; - new__label alias for $3; -- default null - new__description alias for $4; -- default null - new__parent_id alias for $5; - new__extlink_id alias for $6; -- default null - new__creation_date alias for $7; -- default now() - new__creation_user alias for $8; -- default null - new__creation_ip alias for $9; -- default null - new__package_id alias for $10; -- default null +-- old define_function_args('content_extlink__new','name,url,label,description,parent_id,extlink_id,creation_date;now,creation_user,creation_ip,package_id') +-- new +select define_function_args('content_extlink__new','name;null,url,label;null,description;null,parent_id,extlink_id;null,creation_date;now,creation_user;null,creation_ip;null,package_id;null'); + + + + +-- +-- procedure content_extlink__new/10 +-- +CREATE OR REPLACE FUNCTION content_extlink__new( + new__name varchar, -- default null + new__url varchar, + new__label varchar, -- default null + new__description varchar, -- default null + new__parent_id integer, + new__extlink_id integer, -- default null + new__creation_date timestamptz, -- default now() -- default 'now' + new__creation_user integer, -- default null + new__creation_ip varchar, -- default null + new__package_id integer -- default null + +) RETURNS integer AS $$ +DECLARE v_extlink_id cr_extlinks.extlink_id%TYPE; v_package_id acs_objects.package_id%TYPE; v_label cr_extlinks.label%TYPE; v_name cr_items.name%TYPE; -begin +BEGIN if new__label is null then v_label := new__url; @@ -38,8 +48,8 @@ end if; if new__name is null then - select nextval(''t_acs_object_id_seq'') into v_extlink_id from dual; - v_name := ''link'' || v_extlink_id; + select nextval('t_acs_object_id_seq') into v_extlink_id from dual; + v_name := 'link' || v_extlink_id; else v_name := new__name; end if; @@ -59,14 +69,14 @@ new__creation_user, null, new__creation_ip, - ''content_item'', - ''content_extlink'', + 'content_item', + 'content_extlink', null, null, - ''text/plain'', + 'text/plain', null, null, - ''text'', + 'text', v_package_id ); @@ -81,21 +91,31 @@ return v_extlink_id; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create or replace function content_extlink__new (varchar,varchar,varchar,varchar,integer,integer,timestamptz,integer,varchar) -returns integer as ' -declare - new__name alias for $1; -- default null - new__url alias for $2; - new__label alias for $3; -- default null - new__description alias for $4; -- default null - new__parent_id alias for $5; - new__extlink_id alias for $6; -- default null - new__creation_date alias for $7; -- default now() - new__creation_user alias for $8; -- default null - new__creation_ip alias for $9; -- default null -begin + + +-- +-- procedure content_extlink__new/9 +-- +CREATE OR REPLACE FUNCTION content_extlink__new( + new__name varchar, -- default null + new__url varchar, + new__label varchar, -- default null + new__description varchar, -- default null + new__parent_id integer, + new__extlink_id integer, -- default null + new__creation_date timestamptz, -- default now() + new__creation_user integer, -- default null + new__creation_ip varchar -- default null + +) RETURNS integer AS $$ +-- +-- content_extlink__new/9 maybe obsolete, when we define proper defaults for /10 +-- +DECLARE +BEGIN return content_extlink__new(new__name, new__url, new__label, @@ -108,31 +128,43 @@ null ); -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select define_function_args('content_extlink__delete','extlink_id'); -create or replace function content_extlink__delete (integer) -returns integer as ' -declare - delete__extlink_id alias for $1; -begin + +-- +-- procedure content_extlink__delete/1 +-- +CREATE OR REPLACE FUNCTION content_extlink__delete( + delete__extlink_id integer +) RETURNS integer AS $$ +DECLARE +BEGIN + delete from cr_extlinks where extlink_id = delete__extlink_id; PERFORM content_item__delete(delete__extlink_id); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select define_function_args('content_extlink__is_extlink','item_id'); -create or replace function content_extlink__is_extlink (integer) -returns boolean as ' -declare - is_extlink__item_id alias for $1; + + +-- +-- procedure content_extlink__is_extlink/1 +-- +CREATE OR REPLACE FUNCTION content_extlink__is_extlink( + is_extlink__item_id integer +) RETURNS boolean AS $$ +DECLARE v_extlink_p boolean; -begin +BEGIN select count(1) = 1 into v_extlink_p @@ -143,21 +175,27 @@ return v_extlink_p; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create or replace function content_extlink__copy ( - integer, - integer, - integer, - varchar) -returns integer as ' -declare - copy__extlink_id alias for $1; - copy__target_folder_id alias for $2; - copy__creation_user alias for $3; - copy__creation_ip alias for $4; -- default null + + +-- +-- procedure content_extlink__copy/4 +-- +CREATE OR REPLACE FUNCTION content_extlink__copy( + copy__extlink_id integer, + copy__target_folder_id integer, + copy__creation_user integer, + copy__creation_ip varchar -- default null + +) RETURNS integer AS $$ +-- +-- content_extlink__copy/4 maybe obsolete, when we define proper defaults for /5 +-- +DECLARE v_extlink_id cr_extlinks.extlink_id%TYPE; -begin +BEGIN v_extlink_id := content_extlink__copy ( copy__extlink_id, copy__target_folder_id, @@ -166,31 +204,37 @@ NULL ); return 0; -end;' language 'plpgsql' stable; +END; +$$ LANGUAGE plpgsql stable; -select define_function_args('content_extlink__copy','extlink_id,target_folder_id,creation_user,creation_ip,name'); -create or replace function content_extlink__copy ( - integer, - integer, - integer, - varchar, - varchar) -returns integer as ' -declare - copy__extlink_id alias for $1; - copy__target_folder_id alias for $2; - copy__creation_user alias for $3; - copy__creation_ip alias for $4; -- default null - copy__name alias for $5; + +-- old define_function_args('content_extlink__copy','extlink_id,target_folder_id,creation_user,creation_ip,name') +-- new +select define_function_args('content_extlink__copy','extlink_id,target_folder_id,creation_user,creation_ip;null,name'); + + + +-- +-- procedure content_extlink__copy/5 +-- +CREATE OR REPLACE FUNCTION content_extlink__copy( + copy__extlink_id integer, + copy__target_folder_id integer, + copy__creation_user integer, + copy__creation_ip varchar, -- default null + copy__name varchar + +) RETURNS integer AS $$ +DECLARE v_current_folder_id cr_folders.folder_id%TYPE; v_name cr_items.name%TYPE; v_url cr_extlinks.url%TYPE; v_description cr_extlinks.description%TYPE; v_label cr_extlinks.label%TYPE; v_extlink_id cr_extlinks.extlink_id%TYPE; -begin +BEGIN - if content_folder__is_folder(copy__target_folder_id) = ''t'' then + if content_folder__is_folder(copy__target_folder_id) = 't' then select parent_id into @@ -200,7 +244,7 @@ where item_id = copy__extlink_id; - -- can''t copy to the same folder + -- can't copy to the same folder select i.name, e.url, e.description, e.label @@ -218,7 +262,7 @@ if copy__target_folder_id != v_current_folder_id or ( v_name <> copy__name and copy__name is not null ) then if content_folder__is_registered(copy__target_folder_id, - ''content_extlink'',''f'') = ''t'' then + 'content_extlink','f') = 't' then v_extlink_id := content_extlink__new( coalesce (copy__name, v_name), @@ -238,7 +282,8 @@ end if; return 0; -end;' language 'plpgsql' stable; +END; +$$ LANGUAGE plpgsql stable; Index: openacs-4/packages/acs-content-repository/sql/postgresql/content-folder.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/sql/postgresql/content-folder.sql,v diff -u -r1.50 -r1.51 --- openacs-4/packages/acs-content-repository/sql/postgresql/content-folder.sql 24 Oct 2008 13:50:14 -0000 1.50 +++ openacs-4/packages/acs-content-repository/sql/postgresql/content-folder.sql 7 Jul 2011 10:46:02 -0000 1.51 @@ -13,15 +13,24 @@ -- create or replace package body content_folder -create or replace function content_folder__new(varchar,varchar,varchar,integer,integer) -returns integer as ' -declare - new__name alias for $1; - new__label alias for $2; - new__description alias for $3; -- default null - new__parent_id alias for $4; -- default null - new__package_id alias for $5; -- default null -begin + + +-- +-- procedure content_folder__new/5 +-- +CREATE OR REPLACE FUNCTION content_folder__new( + new__name varchar, + new__label varchar, + new__description varchar, -- default null + new__parent_id integer, -- default null + new__package_id integer -- default null + +) RETURNS integer AS $$ +-- +-- content_folder__new/5 maybe obsolete, when we define proper defaults for /11 +-- +DECLARE +BEGIN return content_folder__new(new__name, new__label, new__description, @@ -34,16 +43,26 @@ new__package_id ); -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create or replace function content_folder__new(varchar,varchar,varchar,integer) -returns integer as ' -declare - new__name alias for $1; - new__label alias for $2; - new__description alias for $3; -- default null - new__parent_id alias for $4; -- default null -begin + + +-- +-- procedure content_folder__new/4 +-- +CREATE OR REPLACE FUNCTION content_folder__new( + new__name varchar, + new__label varchar, + new__description varchar, -- default null + new__parent_id integer -- default null + +) RETURNS integer AS $$ +-- +-- content_folder__new/4 maybe obsolete, when we define proper defaults for /11 +-- +DECLARE +BEGIN return content_folder__new(new__name, new__label, new__description, @@ -53,26 +72,36 @@ now(), null, null, - ''t'', + 't', null ); -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function new -create or replace function content_folder__new (varchar,varchar,varchar,integer,integer,integer,timestamptz,integer,varchar) -returns integer as ' -declare - new__name alias for $1; - new__label alias for $2; - new__description alias for $3; -- default null - new__parent_id alias for $4; -- default null - new__context_id alias for $5; -- default null - new__folder_id alias for $6; -- default null - new__creation_date alias for $7; -- default now() - new__creation_user alias for $8; -- default null - new__creation_ip alias for $9; -- default null -begin + + +-- +-- procedure content_folder__new/9 +-- +CREATE OR REPLACE FUNCTION content_folder__new( + new__name varchar, + new__label varchar, + new__description varchar, -- default null + new__parent_id integer, -- default null + new__context_id integer, -- default null + new__folder_id integer, -- default null + new__creation_date timestamptz, -- default now() + new__creation_user integer, -- default null + new__creation_ip varchar -- default null + +) RETURNS integer AS $$ +-- +-- content_folder__new/9 maybe obsolete, when we define proper defaults for /11 +-- +DECLARE +BEGIN return content_folder__new(new__name, new__label, new__description, @@ -82,30 +111,40 @@ new__creation_date, new__creation_user, new__creation_ip, - ''t'', + 't', null::integer ); -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function new -create or replace function content_folder__new (varchar,varchar,varchar,integer,integer,integer,timestamptz,integer,varchar,integer) -returns integer as ' -declare - new__name alias for $1; - new__label alias for $2; - new__description alias for $3; -- default null - new__parent_id alias for $4; -- default null - new__context_id alias for $5; -- default null - new__folder_id alias for $6; -- default null - new__creation_date alias for $7; -- default now() - new__creation_user alias for $8; -- default null - new__creation_ip alias for $9; -- default null - new__package_id alias for $10; -- default null + + +-- +-- procedure content_folder__new/10 +-- +CREATE OR REPLACE FUNCTION content_folder__new( + new__name varchar, + new__label varchar, + new__description varchar, -- default null + new__parent_id integer, -- default null + new__context_id integer, -- default null + new__folder_id integer, -- default null + new__creation_date timestamptz, -- default now() + new__creation_user integer, -- default null + new__creation_ip varchar, -- default null + new__package_id integer -- default null + +) RETURNS integer AS $$ +-- +-- content_folder__new/10 maybe obsolete, when we define proper defaults for /11 +-- +DECLARE v_folder_id cr_folders.folder_id%TYPE; v_context_id acs_objects.context_id%TYPE; v_package_id acs_objects.package_id%TYPE; -begin +BEGIN return content_folder__new(new__name, new__label, new__description, @@ -115,28 +154,38 @@ new__creation_date, new__creation_user, new__creation_ip, - ''t'', + 't', new__package_id ); -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create or replace function content_folder__new (varchar,varchar,varchar,integer,integer,integer,timestamptz,integer,varchar,boolean) -returns integer as ' -declare - new__name alias for $1; - new__label alias for $2; - new__description alias for $3; -- default null - new__parent_id alias for $4; -- default null - new__context_id alias for $5; -- default null - new__folder_id alias for $6; -- default null - new__creation_date alias for $7; -- default now() - new__creation_user alias for $8; -- default null - new__creation_ip alias for $9; -- default null - new__security_inherit_p alias for $10; -- default true + + +-- +-- procedure content_folder__new/10 +-- +CREATE OR REPLACE FUNCTION content_folder__new( + new__name varchar, + new__label varchar, + new__description varchar, -- default null + new__parent_id integer, -- default null + new__context_id integer, -- default null + new__folder_id integer, -- default null + new__creation_date timestamptz, -- default now() + new__creation_user integer, -- default null + new__creation_ip varchar, -- default null + new__security_inherit_p boolean -- default true + +) RETURNS integer AS $$ +-- +-- content_folder__new/10 maybe obsolete, when we define proper defaults for /11 +-- +DECLARE v_package_id acs_objects.package_id%TYPE; v_folder_id cr_folders.folder_id%TYPE; v_context_id acs_objects.context_id%TYPE; -begin +BEGIN return content_folder__new ( new__name, @@ -152,28 +201,39 @@ null ); -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function new -- accepts security_inherit_p DaveB -select define_function_args('content_folder__new','name,label,description,parent_id,context_id,folder_id,creation_date;now,creation_user,creation_ip,security_inherit_p;t,package_id'); -create or replace function content_folder__new (varchar,varchar,varchar,integer,integer,integer,timestamptz,integer,varchar, boolean,integer) -returns integer as ' -declare - new__name alias for $1; - new__label alias for $2; - new__description alias for $3; -- default null - new__parent_id alias for $4; -- default null - new__context_id alias for $5; -- default null - new__folder_id alias for $6; -- default null - new__creation_date alias for $7; -- default now() - new__creation_user alias for $8; -- default null - new__creation_ip alias for $9; -- default null - new__security_inherit_p alias for $10; -- default true - new__package_id alias for $11; -- default null +-- old define_function_args('content_folder__new','name,label,description,parent_id,context_id,folder_id,creation_date;now,creation_user,creation_ip,security_inherit_p;t,package_id') +-- new +select define_function_args('content_folder__new','name,label,description;null,parent_id;null,context_id;null,folder_id;null,creation_date;now,creation_user;null,creation_ip;null,security_inherit_p;t,package_id;null'); + + + + +-- +-- procedure content_folder__new/11 +-- +CREATE OR REPLACE FUNCTION content_folder__new( + new__name varchar, + new__label varchar, + new__description varchar, -- default null + new__parent_id integer, -- default null + new__context_id integer, -- default null + new__folder_id integer, -- default null + new__creation_date timestamptz, -- default now() -- default 'now' + new__creation_user integer, -- default null + new__creation_ip varchar, -- default null + new__security_inherit_p boolean, -- default true -- default 't' + new__package_id integer -- default null + +) RETURNS integer AS $$ +DECLARE v_folder_id cr_folders.folder_id%TYPE; v_context_id acs_objects.context_id%TYPE; -begin +BEGIN -- set the context_id if new__context_id is null then @@ -185,9 +245,9 @@ -- parent_id = security_context_root means that this is a mount point if new__parent_id != -4 and content_folder__is_folder(new__parent_id) and - content_folder__is_registered(new__parent_id,''content_folder'',''f'') = ''f'' then + content_folder__is_registered(new__parent_id,'content_folder','f') = 'f' then - raise EXCEPTION ''-20000: This folder does not allow subfolders to be created''; + raise EXCEPTION '-20000: This folder does not allow subfolders to be created'; return null; else @@ -201,14 +261,14 @@ new__creation_user, new__context_id, new__creation_ip, - ''f'', - ''text/plain'', + 'f', + 'text/plain', null, - ''text'', + 'text', new__security_inherit_p, - ''CR_FILES'', - ''content_folder'', - ''content_folder'', + 'CR_FILES', + 'content_folder', + 'content_folder', new__package_id ); @@ -237,30 +297,40 @@ end if; -- update the child flag on the parent - update cr_folders set has_child_folders = ''t'' + update cr_folders set has_child_folders = 't' where folder_id = new__parent_id; return v_folder_id; end if; return v_folder_id; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create or replace function content_folder__new (varchar,varchar,varchar,integer,integer,integer,timestamptz,integer,varchar,boolean) -returns integer as ' -declare - new__name alias for $1; - new__label alias for $2; - new__description alias for $3; -- default null - new__parent_id alias for $4; -- default null - new__context_id alias for $5; -- default null - new__folder_id alias for $6; -- default null - new__creation_date alias for $7; -- default now() - new__creation_user alias for $8; -- default null - new__creation_ip alias for $9; -- default null - new__security_inherit_p alias for $10; -- default true -begin + + +-- +-- procedure content_folder__new/10 +-- +CREATE OR REPLACE FUNCTION content_folder__new( + new__name varchar, + new__label varchar, + new__description varchar, -- default null + new__parent_id integer, -- default null + new__context_id integer, -- default null + new__folder_id integer, -- default null + new__creation_date timestamptz, -- default now() + new__creation_user integer, -- default null + new__creation_ip varchar, -- default null + new__security_inherit_p boolean -- default true + +) RETURNS integer AS $$ +-- +-- content_folder__new/10 maybe obsolete, when we define proper defaults for /11 +-- +DECLARE +BEGIN return content_folder__new(new__name, new__label, new__description, @@ -274,29 +344,36 @@ null::integer ); -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure delete select define_function_args('content_folder__del','folder_id,cascade_p;f'); -create or replace function content_folder__del (integer, boolean) -returns integer as ' -declare - delete__folder_id alias for $1; - p_cascade_p alias for $2; -- default ''f'' + + +-- +-- procedure content_folder__del/2 +-- +CREATE OR REPLACE FUNCTION content_folder__del( + delete__folder_id integer, + p_cascade_p boolean -- default 'f' + +) RETURNS integer AS $$ +DECLARE v_count integer; v_child_row record; v_parent_id integer; v_path varchar; v_folder_sortkey varbit; -begin +BEGIN - if p_cascade_p = ''f'' then + if p_cascade_p = 'f' then select count(*) into v_count from cr_items where parent_id = delete__folder_id; -- check if the folder contains any items if v_count > 0 then v_path := content_item__get_path(delete__folder_id, null); - raise EXCEPTION ''-20000: Folder ID % (%) cannot be deleted because it is not empty.'', delete__folder_id, v_path; + raise EXCEPTION '-20000: Folder ID % (%) cannot be deleted because it is not empty.', delete__folder_id, v_path; end if; else -- delete children @@ -320,95 +397,123 @@ PERFORM content_folder__unregister_content_type( delete__folder_id, - ''content_revision'', - ''t'' + 'content_revision', + 't' ); delete from cr_folder_type_map where folder_id = delete__folder_id; select parent_id into v_parent_id from cr_items where item_id = delete__folder_id; - raise notice ''deleteing folder %'',delete__folder_id; + raise notice 'deleteing folder %',delete__folder_id; PERFORM content_item__delete(delete__folder_id); -- check if any folders are left in the parent - update cr_folders set has_child_folders = ''f'' + update cr_folders set has_child_folders = 'f' where folder_id = v_parent_id and not exists ( select 1 from cr_items - where parent_id = v_parent_id and content_type = ''content_folder''); + where parent_id = v_parent_id and content_type = 'content_folder'); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select define_function_args('content_folder__delete','folder_id,cascade_p;f'); -create or replace function content_folder__delete (integer, boolean) -returns integer as ' -declare - delete__folder_id alias for $1; - p_cascade_p alias for $2; -- default ''f'' -begin + + +-- +-- procedure content_folder__delete/2 +-- +CREATE OR REPLACE FUNCTION content_folder__delete( + delete__folder_id integer, + p_cascade_p boolean -- default 'f' + +) RETURNS integer AS $$ +DECLARE +BEGIN PERFORM content_folder__del(delete__folder_id,p_cascade_p); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create or replace function content_folder__delete (integer) -returns integer as ' -declare - delete__folder_id alias for $1; + + +-- +-- procedure content_folder__delete/1 +-- +CREATE OR REPLACE FUNCTION content_folder__delete( + delete__folder_id integer +) RETURNS integer AS $$ +-- +-- content_folder__delete/1 maybe obsolete, when we define proper defaults for /2 +-- +DECLARE v_count integer; v_parent_id integer; v_path varchar; -begin +BEGIN return content_folder__del( delete__folder_id, - ''f'' + 'f' ); -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure rename -select define_function_args('content_folder__edit_name','folder_id,name,label,description'); -create or replace function content_folder__edit_name (integer,varchar,varchar,varchar) -returns integer as ' -declare - edit_name__folder_id alias for $1; - edit_name__name alias for $2; -- default null - edit_name__label alias for $3; -- default null - edit_name__description alias for $4; -- default null + +-- old define_function_args('content_folder__edit_name','folder_id,name,label,description') +-- new +select define_function_args('content_folder__edit_name','folder_id,name;null,label;null,description;null'); + + + +-- +-- procedure content_folder__edit_name/4 +-- +CREATE OR REPLACE FUNCTION content_folder__edit_name( + edit_name__folder_id integer, + edit_name__name varchar, -- default null + edit_name__label varchar, -- default null + edit_name__description varchar -- default null + +) RETURNS integer AS $$ +DECLARE v_name_already_exists_p integer; -begin +BEGIN - if edit_name__name is not null and edit_name__name != '''' then + if edit_name__name is not null and edit_name__name != '' then PERFORM content_item__edit_name(edit_name__folder_id, edit_name__name); end if; - if edit_name__label is not null and edit_name__label != '''' then + if edit_name__label is not null and edit_name__label != '' then update acs_objects set title = edit_name__label where object_id = edit_name__folder_id; end if; - if edit_name__label is not null and edit_name__label != '''' and - edit_name__description is not null and edit_name__description != '''' then + if edit_name__label is not null and edit_name__label != '' and + edit_name__description is not null and edit_name__description != '' then update cr_folders set label = edit_name__label, description = edit_name__description where folder_id = edit_name__folder_id; - else if(edit_name__label is not null and edit_name__label != '''') and - (edit_name__description is null or edit_name__description = '''') then + else if(edit_name__label is not null and edit_name__label != '') and + (edit_name__description is null or edit_name__description = '') then update cr_folders set label = edit_name__label where folder_id = edit_name__folder_id; end if; end if; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- 1) make sure we are not moving the folder to an invalid location: -- a. destination folder exists @@ -421,15 +526,21 @@ -- procedure move select define_function_args('content_folder__move','folder_id,target_folder_id,name;null'); -create or replace function content_folder__move (integer,integer,varchar) -returns integer as ' -declare - move__folder_id alias for $1; - move__target_folder_id alias for $2; - move__name alias for $3; -- default null + + +-- +-- procedure content_folder__move/3 +-- +CREATE OR REPLACE FUNCTION content_folder__move( + move__folder_id integer, + move__target_folder_id integer, + move__name varchar -- default null + +) RETURNS integer AS $$ +DECLARE v_source_folder_id integer; v_valid_folders_p integer; -begin +BEGIN select count(*) @@ -443,24 +554,24 @@ folder_id = move__folder_id; if v_valid_folders_p != 2 then - raise EXCEPTION ''-20000: content_folder.move - Not valid folder(s)''; + raise EXCEPTION '-20000: content_folder.move - Not valid folder(s)'; end if; if move__folder_id = content_item__get_root_folder(null) or move__folder_id = content_template__get_root_folder() then - raise EXCEPTION ''-20000: content_folder.move - Cannot move root folder''; + raise EXCEPTION '-20000: content_folder.move - Cannot move root folder'; end if; if move__target_folder_id = move__folder_id then - raise EXCEPTION ''-20000: content_folder.move - Cannot move a folder to itself''; + raise EXCEPTION '-20000: content_folder.move - Cannot move a folder to itself'; end if; - if content_folder__is_sub_folder(move__folder_id, move__target_folder_id) = ''t'' then - raise EXCEPTION ''-20000: content_folder.move - Destination folder is subfolder''; + if content_folder__is_sub_folder(move__folder_id, move__target_folder_id) = 't' then + raise EXCEPTION '-20000: content_folder.move - Destination folder is subfolder'; end if; - if content_folder__is_registered(move__target_folder_id,''content_folder'',''f'') != ''t'' then - raise EXCEPTION ''-20000: content_folder.move - Destination folder does not allow subfolders''; + if content_folder__is_registered(move__target_folder_id,'content_folder','f') != 't' then + raise EXCEPTION '-20000: content_folder.move - Destination folder does not allow subfolders'; end if; select parent_id into v_source_folder_id from cr_items @@ -475,50 +586,68 @@ -- update the has_child_folders flags -- update the source - update cr_folders set has_child_folders = ''f'' + update cr_folders set has_child_folders = 'f' where folder_id = v_source_folder_id and not exists ( select 1 from cr_items where parent_id = v_source_folder_id - and content_type = ''content_folder''); + and content_type = 'content_folder'); -- update the destination - update cr_folders set has_child_folders = ''t'' + update cr_folders set has_child_folders = 't' where folder_id = move__target_folder_id; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create or replace function content_folder__move (integer,integer) -returns integer as ' -declare - move__folder_id alias for $1; - move__target_folder_id alias for $2; -begin + +-- +-- procedure content_folder__move/2 +-- +CREATE OR REPLACE FUNCTION content_folder__move( + move__folder_id integer, + move__target_folder_id integer +) RETURNS integer AS $$ +-- +-- content_folder__move/2 maybe obsolete, when we define proper defaults for /3 +-- +DECLARE +BEGIN + perform content_folder__move ( move__folder_id, move__target_folder_id, NULL ); return null; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure copy -create or replace function content_folder__copy (integer,integer,integer,varchar) -returns integer as ' -declare - copy__folder_id alias for $1; - copy__target_folder_id alias for $2; - copy__creation_user alias for $3; - copy__creation_ip alias for $4; -- default null + + +-- added + +-- +-- procedure content_folder__copy/4 +-- +CREATE OR REPLACE FUNCTION content_folder__copy( + copy__folder_id integer, + copy__target_folder_id integer, + copy__creation_user integer, + copy__creation_ip varchar -- default null + +) RETURNS integer AS $$ +DECLARE v_valid_folders_p integer; v_current_folder_id cr_folders.folder_id%TYPE; v_name cr_items.name%TYPE; v_label cr_folders.label%TYPE; v_description cr_folders.description%TYPE; v_new_folder_id cr_folders.folder_id%TYPE; v_folder_contents_val record; -begin +BEGIN v_new_folder_id := content_folder__copy ( copy__folder_id, copy__target_folder_id, @@ -527,28 +656,38 @@ NULL ); return v_new_folder_id; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create or replace function content_folder__copy (integer,integer,integer,varchar,varchar) -returns integer as ' -declare - copy__folder_id alias for $1; - copy__target_folder_id alias for $2; - copy__creation_user alias for $3; - copy__creation_ip alias for $4; -- default null - copy__name alias for $5; -- default null + + +-- added +select define_function_args('content_folder__copy','folder_id,target_folder_id,creation_user,creation_ip;null,name;null'); + +-- +-- procedure content_folder__copy/5 +-- +CREATE OR REPLACE FUNCTION content_folder__copy( + copy__folder_id integer, + copy__target_folder_id integer, + copy__creation_user integer, + copy__creation_ip varchar, -- default null + copy__name varchar -- default null + +) RETURNS integer AS $$ +DECLARE v_valid_folders_p integer; v_current_folder_id cr_folders.folder_id%TYPE; v_name cr_items.name%TYPE; v_label cr_folders.label%TYPE; v_description cr_folders.description%TYPE; v_new_folder_id cr_folders.folder_id%TYPE; v_folder_contents_val record; -begin +BEGIN if copy__folder_id = content_item__get_root_folder(null) or copy__folder_id = content_template__get_root_folder() then - raise EXCEPTION ''-20000: content_folder.copy - Not allowed to copy root folder''; + raise EXCEPTION '-20000: content_folder.copy - Not allowed to copy root folder'; end if; select @@ -563,19 +702,19 @@ folder_id = copy__folder_id; if v_valid_folders_p != 2 then - raise EXCEPTION ''-20000: content_folder.copy - Invalid folder(s)''; + raise EXCEPTION '-20000: content_folder.copy - Invalid folder(s)'; end if; if copy__target_folder_id = copy__folder_id then - raise EXCEPTION ''-20000: content_folder.copy - Cannot copy folder to itself''; + raise EXCEPTION '-20000: content_folder.copy - Cannot copy folder to itself'; end if; - if content_folder__is_sub_folder(copy__folder_id, copy__target_folder_id) = ''t'' then - raise EXCEPTION ''-20000: content_folder.copy - Destination folder is subfolder''; + if content_folder__is_sub_folder(copy__folder_id, copy__target_folder_id) = 't' then + raise EXCEPTION '-20000: content_folder.copy - Destination folder is subfolder'; end if; - if content_folder__is_registered(copy__target_folder_id,''content_folder'',''f'') != ''t'' then - raise EXCEPTION ''-20000: content_folder.copy - Destination folder does not allow subfolders''; + if content_folder__is_registered(copy__target_folder_id,'content_folder','f') != 't' then + raise EXCEPTION '-20000: content_folder.copy - Destination folder does not allow subfolders'; end if; -- get the source folder info @@ -593,7 +732,7 @@ -- would be better to check if the copy__name alredy exists in the destination folder. if v_current_folder_id = copy__target_folder_id and (v_name = copy__name or copy__name is null) then - raise EXCEPTION ''-20000: content_folder.copy - Destination folder is parent folder and folder alredy exists''; + raise EXCEPTION '-20000: content_folder.copy - Destination folder is parent folder and folder alredy exists'; end if; -- create the new folder @@ -607,7 +746,7 @@ now(), copy__creation_user, copy__creation_ip, - ''t'', + 't', null ); @@ -645,39 +784,51 @@ end loop; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function is_folder select define_function_args('content_folder__is_folder','item_id'); -create or replace function content_folder__is_folder (integer) -returns boolean as ' -declare - item_id alias for $1; -begin + +-- +-- procedure content_folder__is_folder/1 +-- +CREATE OR REPLACE FUNCTION content_folder__is_folder( + item_id integer +) RETURNS boolean AS $$ +DECLARE +BEGIN + return count(*) > 0 from cr_folders where folder_id = item_id; -end;' language 'plpgsql' stable; +END; +$$ LANGUAGE plpgsql stable; -- function is_sub_folder select define_function_args('content_folder__is_sub_folder','folder_id,target_folder_id'); -create or replace function content_folder__is_sub_folder (integer,integer) -returns boolean as ' -declare - is_sub_folder__folder_id alias for $1; - is_sub_folder__target_folder_id alias for $2; + + +-- +-- procedure content_folder__is_sub_folder/2 +-- +CREATE OR REPLACE FUNCTION content_folder__is_sub_folder( + is_sub_folder__folder_id integer, + is_sub_folder__target_folder_id integer +) RETURNS boolean AS $$ +DECLARE v_parent_id integer default 0; - v_sub_folder_p boolean default ''f''; + v_sub_folder_p boolean default 'f'; v_rec record; -begin +BEGIN if is_sub_folder__folder_id = content_item__get_root_folder(null) or is_sub_folder__folder_id = content_template__get_root_folder() then - v_sub_folder_p := ''t''; + v_sub_folder_p := 't'; end if; -- select @@ -702,22 +853,28 @@ end LOOP; if v_parent_id != -4 then - v_sub_folder_p := ''t''; + v_sub_folder_p := 't'; end if; return v_sub_folder_p; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function is_empty select define_function_args('content_folder__is_empty','folder_id'); -create or replace function content_folder__is_empty (integer) -returns boolean as ' -declare - is_empty__folder_id alias for $1; + + +-- +-- procedure content_folder__is_empty/1 +-- +CREATE OR REPLACE FUNCTION content_folder__is_empty( + is_empty__folder_id integer +) RETURNS boolean AS $$ +DECLARE v_return boolean; -begin +BEGIN select count(*) = 0 into v_return @@ -728,30 +885,37 @@ return v_return; -end;' language 'plpgsql' stable; +END; +$$ LANGUAGE plpgsql stable; -- procedure register_content_type select define_function_args('content_folder__register_content_type','folder_id,content_type,include_subtypes;f'); -create or replace function content_folder__register_content_type (integer,varchar,boolean) -returns integer as ' -declare - register_content_type__folder_id alias for $1; - register_content_type__content_type alias for $2; - register_content_type__include_subtypes alias for $3; -- default ''f'' + + +-- +-- procedure content_folder__register_content_type/3 +-- +CREATE OR REPLACE FUNCTION content_folder__register_content_type( + register_content_type__folder_id integer, + register_content_type__content_type varchar, + register_content_type__include_subtypes boolean -- default 'f' + +) RETURNS integer AS $$ +DECLARE v_is_registered varchar; -begin +BEGIN - if register_content_type__include_subtypes = ''f'' then + if register_content_type__include_subtypes = 'f' then v_is_registered := content_folder__is_registered( register_content_type__folder_id, register_content_type__content_type, - ''f'' + 'f' ); - if v_is_registered = ''f'' then + if v_is_registered = 'f' then insert into cr_folder_type_map ( folder_id, content_type @@ -771,7 +935,7 @@ -- from -- acs_object_types -- where --- object_type <> ''acs_object'' +-- object_type <> 'acs_object' -- and -- not exists (select 1 from cr_folder_type_map -- where folder_id = register_content_type__folder_id @@ -785,7 +949,7 @@ select register_content_type__folder_id as folder_id, o.object_type as content_type from acs_object_types o, acs_object_types o2 - where o.object_type <> ''acs_object'' + where o.object_type <> 'acs_object' and not exists (select 1 from cr_folder_type_map where folder_id = register_content_type__folder_id @@ -795,20 +959,27 @@ end if; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure unregister_content_type select define_function_args('content_folder__unregister_content_type','folder_id,content_type,include_subtypes;f'); -create or replace function content_folder__unregister_content_type (integer,varchar,boolean) -returns integer as ' -declare - unregister_content_type__folder_id alias for $1; - unregister_content_type__content_type alias for $2; - unregister_content_type__include_subtypes alias for $3; -- default ''f'' -begin - if unregister_content_type__include_subtypes = ''f'' then + +-- +-- procedure content_folder__unregister_content_type/3 +-- +CREATE OR REPLACE FUNCTION content_folder__unregister_content_type( + unregister_content_type__folder_id integer, + unregister_content_type__content_type varchar, + unregister_content_type__include_subtypes boolean -- default 'f' + +) RETURNS integer AS $$ +DECLARE +BEGIN + + if unregister_content_type__include_subtypes = 'f' then delete from cr_folder_type_map where folder_id = unregister_content_type__folder_id and content_type = unregister_content_type__content_type; @@ -818,7 +989,7 @@ -- where folder_id = unregister_content_type__folder_id -- and content_type in (select object_type -- from acs_object_types --- where object_type <> ''acs_object'' +-- where object_type <> 'acs_object' -- connect by prior object_type = supertype -- start with -- object_type = unregister_content_type__content_type); @@ -827,29 +998,36 @@ where folder_id = unregister_content_type__folder_id and content_type in (select o.object_type from acs_object_types o, acs_object_types o2 - where o.object_type <> ''acs_object'' + where o.object_type <> 'acs_object' and o2.object_type = unregister_content_type__content_type and o.tree_sortkey between o2.tree_sortkey and tree_right(o2.tree_sortkey)); end if; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function is_registered select define_function_args('content_folder__is_registered','folder_id,content_type,include_subtypes;f'); -create or replace function content_folder__is_registered (integer,varchar,boolean) -returns boolean as ' -declare - is_registered__folder_id alias for $1; - is_registered__content_type alias for $2; - is_registered__include_subtypes alias for $3; -- default ''f'' + + +-- +-- procedure content_folder__is_registered/3 +-- +CREATE OR REPLACE FUNCTION content_folder__is_registered( + is_registered__folder_id integer, + is_registered__content_type varchar, + is_registered__include_subtypes boolean -- default 'f' + +) RETURNS boolean AS $$ +DECLARE v_is_registered integer; v_subtype_val record; -begin +BEGIN - if is_registered__include_subtypes = ''f'' or is_registered__include_subtypes is null then + if is_registered__include_subtypes = 'f' or is_registered__include_subtypes is null then select count(1) into @@ -867,7 +1045,7 @@ -- from -- acs_object_types -- where --- object_type <> ''acs_object'' +-- object_type <> 'acs_object' -- connect by -- prior object_type = supertype -- start with @@ -876,35 +1054,41 @@ v_is_registered := 1; for v_subtype_val in select o.object_type from acs_object_types o, acs_object_types o2 - where o.object_type <> ''acs_object'' + where o.object_type <> 'acs_object' and o2.object_type = is_registered__content_type and o.tree_sortkey between o2.tree_sortkey and tree_right(o2.tree_sortkey) order by o.tree_sortkey LOOP if content_folder__is_registered(is_registered__folder_id, - v_subtype_val.object_type, ''f'') = ''f'' then + v_subtype_val.object_type, 'f') = 'f' then v_is_registered := 0; end if; end loop; end if; if v_is_registered = 0 then - return ''f''; + return 'f'; else - return ''t''; + return 't'; end if; -end;' language 'plpgsql' stable; +END; +$$ LANGUAGE plpgsql stable; -- function get_label select define_function_args('content_folder__get_label','folder_id'); -create or replace function content_folder__get_label (integer) -returns varchar as ' -declare - get_label__folder_id alias for $1; + + +-- +-- procedure content_folder__get_label/1 +-- +CREATE OR REPLACE FUNCTION content_folder__get_label( + get_label__folder_id integer +) RETURNS varchar AS $$ +DECLARE v_label cr_folders.label%TYPE; -begin +BEGIN select label into v_label @@ -915,21 +1099,27 @@ return v_label; -end;' language 'plpgsql' stable strict; +END; +$$ LANGUAGE plpgsql stable strict; -- function get_index_page select define_function_args('content_folder__get_index_page','folder_id'); -create or replace function content_folder__get_index_page (integer) -returns integer as ' -declare - get_index_page__folder_id alias for $1; + + +-- +-- procedure content_folder__get_index_page/1 +-- +CREATE OR REPLACE FUNCTION content_folder__get_index_page( + get_index_page__folder_id integer +) RETURNS integer AS $$ +DECLARE v_folder_id cr_folders.folder_id%TYPE; v_index_page_id cr_items.item_id%TYPE; -begin +BEGIN -- if the folder is a symlink, resolve it - if content_symlink__is_symlink(get_index_page__folder_id) = ''t'' then + if content_symlink__is_symlink(get_index_page__folder_id) = 't' then v_folder_id := content_symlink__resolve(get_index_page__folder_id); else v_folder_id := get_index_page__folder_id; @@ -942,40 +1132,47 @@ where parent_id = v_folder_id and - name = ''index'' + name = 'index' and content_item__is_subclass( content_item__get_content_type(content_symlink__resolve(item_id)), - ''content_folder'') = ''f'' + 'content_folder') = 'f' and content_item__is_subclass( content_item__get_content_type(content_symlink__resolve(item_id)), - ''content_template'') = ''f''; + 'content_template') = 'f'; if NOT FOUND then return null; end if; return v_index_page_id; -end;' language 'plpgsql' stable strict; +END; +$$ LANGUAGE plpgsql stable strict; -- function is_root select define_function_args('content_folder__is_root','folder_id'); -create or replace function content_folder__is_root (integer) -returns boolean as ' -declare - is_root__folder_id alias for $1; + + +-- +-- procedure content_folder__is_root/1 +-- +CREATE OR REPLACE FUNCTION content_folder__is_root( + is_root__folder_id integer +) RETURNS boolean AS $$ +DECLARE v_is_root boolean; -begin +BEGIN select parent_id = -4 into v_is_root from cr_items where item_id = is_root__folder_id; return v_is_root; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; Index: openacs-4/packages/acs-content-repository/sql/postgresql/content-image.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/sql/postgresql/content-image.sql,v diff -u -r1.17 -r1.18 --- openacs-4/packages/acs-content-repository/sql/postgresql/content-image.sql 25 Sep 2006 20:25:19 -0000 1.17 +++ openacs-4/packages/acs-content-repository/sql/postgresql/content-image.sql 7 Jul 2011 10:46:02 -0000 1.18 @@ -109,27 +109,36 @@ -- than the standard package_instantiate_object. So we don't bother calling define_function_args -- here. -create or replace function image__new (varchar,integer,integer,integer,varchar,integer,varchar,varchar,varchar,varchar,boolean,timestamptz,varchar,integer,integer,integer,integer) -returns integer as ' - declare - new__name alias for $1; - new__parent_id alias for $2; -- default null - new__item_id alias for $3; -- default null - new__revision_id alias for $4; -- default null - new__mime_type alias for $5; -- default jpeg - new__creation_user alias for $6; -- default null - new__creation_ip alias for $7; -- default null - new__relation_tag alias for $8; -- default null - new__title alias for $9; -- default null - new__description alias for $10; -- default null - new__is_live alias for $11; -- default f - new__publish_date alias for $12; -- default now() - new__path alias for $13; - new__file_size alias for $14; - new__height alias for $15; - new__width alias for $16; - new__package_id alias for $17; -- default null + +-- added +select define_function_args('image__new','name,parent_id;null,item_id;null,revision_id;null,mime_type;jpeg,creation_user;null,creation_ip;null,relation_tag;null,title;null,description;null,is_live;f,publish_date;now(),path,file_size,height,width,package_id;null'); + +-- +-- procedure image__new/17 +-- +CREATE OR REPLACE FUNCTION image__new( + new__name varchar, + new__parent_id integer, -- default null + new__item_id integer, -- default null + new__revision_id integer, -- default null + new__mime_type varchar, -- default jpeg + new__creation_user integer, -- default null + new__creation_ip varchar, -- default null + new__relation_tag varchar, -- default null + new__title varchar, -- default null + new__description varchar, -- default null + new__is_live boolean, -- default f + new__publish_date timestamptz, -- default now() + new__path varchar, + new__file_size integer, + new__height integer, + new__width integer, + new__package_id integer -- default null + +) RETURNS integer AS $$ +DECLARE + new__locale varchar default null; new__nls_language varchar default null; new__creation_date timestamptz default current_timestamp; @@ -138,7 +147,7 @@ v_item_id cr_items.item_id%TYPE; v_package_id acs_objects.package_id%TYPE; v_revision_id cr_revisions.revision_id%TYPE; - begin + BEGIN new__context_id := new__parent_id; if new__package_id is null then @@ -156,14 +165,14 @@ new__creation_user, new__context_id, new__creation_ip, - ''content_item'', - ''image'', + 'content_item', + 'image', null, new__description, new__mime_type, new__nls_language, null, - ''file'', -- storage_type + 'file', -- storage_type v_package_id ); @@ -172,7 +181,7 @@ set relation_tag = new__relation_tag where parent_id = new__parent_id and child_id = new__item_id - and relation_tag = content_item__get_content_type(new__parent_id) || ''-'' || ''image''; + and relation_tag = content_item__get_content_type(new__parent_id) || '-' || 'image'; v_revision_id := content_revision__new ( new__title, @@ -200,37 +209,44 @@ content = new__path where revision_id = v_revision_id; - -- is_live => ''t'' not used as part of content_item.new + -- is_live => 't' not used as part of content_item.new -- because content_item.new does not let developer specify revision_id, -- revision_id is determined in advance - if new__is_live = ''t'' then + if new__is_live = 't' then PERFORM content_item__set_live_revision (v_revision_id); end if; return v_item_id; -end; ' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create or replace function image__new (varchar,integer,integer,integer,varchar,integer,varchar,varchar,varchar,varchar,boolean,timestamptz,varchar,integer,integer,integer - ) returns integer as ' - declare - new__name alias for $1; - new__parent_id alias for $2; -- default null - new__item_id alias for $3; -- default null - new__revision_id alias for $4; -- default null - new__mime_type alias for $5; -- default jpeg - new__creation_user alias for $6; -- default null - new__creation_ip alias for $7; -- default null - new__relation_tag alias for $8; -- default null - new__title alias for $9; -- default null - new__description alias for $10; -- default null - new__is_live alias for $11; -- default f - new__publish_date alias for $12; -- default now() - new__path alias for $13; - new__file_size alias for $14; - new__height alias for $15; - new__width alias for $16; - begin + + +-- +-- procedure image__new/16 +-- +CREATE OR REPLACE FUNCTION image__new( + new__name varchar, + new__parent_id integer, -- default null + new__item_id integer, -- default null + new__revision_id integer, -- default null + new__mime_type varchar, -- default jpeg + new__creation_user integer, -- default null + new__creation_ip varchar, -- default null + new__relation_tag varchar, -- default null + new__title varchar, -- default null + new__description varchar, -- default null + new__is_live boolean, -- default f + new__publish_date timestamptz, -- default now() + new__path varchar, + new__file_size integer, + new__height integer, + new__width integer + +) RETURNS integer AS $$ +DECLARE + BEGIN return image__new(new__name, new__parent_id, new__item_id, @@ -249,37 +265,44 @@ new__width, null ); -end; ' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- DRB's version -create or replace function image__new (varchar,integer,integer,integer,varchar,integer,varchar,varchar,varchar,varchar,varchar, - varchar,timestamptz,integer, integer, integer) returns integer as ' - declare - p_name alias for $1; - p_parent_id alias for $2; -- default null - p_item_id alias for $3; -- default null - p_revision_id alias for $4; -- default null - p_mime_type alias for $5; -- default jpeg - p_creation_user alias for $6; -- default null - p_creation_ip alias for $7; -- default null - p_title alias for $8; -- default null - p_description alias for $9; -- default null - p_storage_type alias for $10; - p_content_type alias for $11; - p_nls_language alias for $12; - p_publish_date alias for $13; - p_height alias for $14; - p_width alias for $15; - p_package_id alias for $16; -- default null + +-- +-- procedure image__new/16 +-- +CREATE OR REPLACE FUNCTION image__new( + p_name varchar, + p_parent_id integer, -- default null + p_item_id integer, -- default null + p_revision_id integer, -- default null + p_mime_type varchar, -- default jpeg + p_creation_user integer, -- default null + p_creation_ip varchar, -- default null + p_title varchar, -- default null + p_description varchar, -- default null + p_storage_type varchar, + p_content_type varchar, + p_nls_language varchar, + p_publish_date timestamptz, + p_height integer, + p_width integer, + p_package_id integer -- default null + +) RETURNS integer AS $$ +DECLARE + v_item_id cr_items.item_id%TYPE; v_revision_id cr_revisions.revision_id%TYPE; v_package_id acs_objects.package_id%TYPE; - begin + BEGIN - if content_item__is_subclass(p_content_type, ''image'') = ''f'' then - raise EXCEPTION ''-20000: image__new can only be called for an image type''; + if content_item__is_subclass(p_content_type, 'image') = 'f' then + raise EXCEPTION '-20000: image__new can only be called for an image type'; end if; if p_package_id is null then @@ -297,7 +320,7 @@ p_creation_user, p_parent_id, p_creation_ip, - ''content_item'', + 'content_item', p_content_type, null, null, @@ -331,27 +354,34 @@ (v_revision_id, p_height, p_width); return v_item_id; -end; ' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create or replace function image__new (varchar,integer,integer,integer,varchar,integer,varchar,varchar,varchar,varchar,varchar, - varchar,timestamptz,integer, integer) returns integer as ' - declare - p_name alias for $1; - p_parent_id alias for $2; -- default null - p_item_id alias for $3; -- default null - p_revision_id alias for $4; -- default null - p_mime_type alias for $5; -- default jpeg - p_creation_user alias for $6; -- default null - p_creation_ip alias for $7; -- default null - p_title alias for $8; -- default null - p_description alias for $9; -- default null - p_storage_type alias for $10; - p_content_type alias for $11; - p_nls_language alias for $12; - p_publish_date alias for $13; - p_height alias for $14; - p_width alias for $15; - begin + + +-- +-- procedure image__new/15 +-- +CREATE OR REPLACE FUNCTION image__new( + p_name varchar, + p_parent_id integer, -- default null + p_item_id integer, -- default null + p_revision_id integer, -- default null + p_mime_type varchar, -- default jpeg + p_creation_user integer, -- default null + p_creation_ip varchar, -- default null + p_title varchar, -- default null + p_description varchar, -- default null + p_storage_type varchar, + p_content_type varchar, + p_nls_language varchar, + p_publish_date timestamptz, + p_height integer, + p_width integer + +) RETURNS integer AS $$ +DECLARE + BEGIN return image__new(p_name, p_parent_id, p_item_id, @@ -369,27 +399,36 @@ p_width, null ); -end; ' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create or replace function image__new_revision(integer, integer, varchar, varchar, timestamptz, varchar, varchar, - integer, varchar, integer, integer, integer) returns integer as ' -declare - p_item_id alias for $1; - p_revision_id alias for $2; - p_title alias for $3; - p_description alias for $4; - p_publish_date alias for $5; - p_mime_type alias for $6; - p_nls_language alias for $7; - p_creation_user alias for $8; - p_creation_ip alias for $9; - p_height alias for $10; - p_width alias for $11; - p_package_id alias for $12; + + +-- added +select define_function_args('image__new_revision','item_id,revision_id,title,description,publish_date,mime_type,nls_language,creation_user,creation_ip,height,width,package_id'); + +-- +-- procedure image__new_revision/12 +-- +CREATE OR REPLACE FUNCTION image__new_revision( + p_item_id integer, + p_revision_id integer, + p_title varchar, + p_description varchar, + p_publish_date timestamptz, + p_mime_type varchar, + p_nls_language varchar, + p_creation_user integer, + p_creation_ip varchar, + p_height integer, + p_width integer, + p_package_id integer +) RETURNS integer AS $$ +DECLARE v_revision_id integer; v_package_id acs_objects.package_id%TYPE; -begin +BEGIN -- We will let the caller fill in the LOB data or file path. if p_package_id is null then @@ -419,24 +458,30 @@ (v_revision_id, p_height, p_width); return v_revision_id; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create or replace function image__new_revision(integer,integer,varchar,varchar,timestamptz,varchar,varchar, - integer,varchar,integer,integer) returns integer as ' -declare - p_item_id alias for $1; - p_revision_id alias for $2; - p_title alias for $3; - p_description alias for $4; - p_publish_date alias for $5; - p_mime_type alias for $6; - p_nls_language alias for $7; - p_creation_user alias for $8; - p_creation_ip alias for $9; - p_height alias for $10; - p_width alias for $11; + + +-- +-- procedure image__new_revision/11 +-- +CREATE OR REPLACE FUNCTION image__new_revision( + p_item_id integer, + p_revision_id integer, + p_title varchar, + p_description varchar, + p_publish_date timestamptz, + p_mime_type varchar, + p_nls_language varchar, + p_creation_user integer, + p_creation_ip varchar, + p_height integer, + p_width integer +) RETURNS integer AS $$ +DECLARE v_revision_id integer; -begin +BEGIN return image__new_revision(p_item_id, p_revision_id, p_title, @@ -452,16 +497,26 @@ null ); -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create or replace function image__delete (integer) -returns integer as ' -declare - v_item_id alias for $1; -begin + +-- added +select define_function_args('image__delete','v_item_id'); + +-- +-- procedure image__delete/1 +-- +CREATE OR REPLACE FUNCTION image__delete( + v_item_id integer +) RETURNS integer AS $$ +DECLARE +BEGIN + -- This should take care of deleting revisions, too. PERFORM content_item__delete (v_item_id); return 0; -end; ' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; Index: openacs-4/packages/acs-content-repository/sql/postgresql/content-item.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/sql/postgresql/content-item.sql,v diff -u -r1.69 -r1.70 --- openacs-4/packages/acs-content-repository/sql/postgresql/content-item.sql 11 Jun 2008 00:08:49 -0000 1.69 +++ openacs-4/packages/acs-content-repository/sql/postgresql/content-item.sql 7 Jul 2011 10:46:02 -0000 1.70 @@ -13,13 +13,23 @@ create or replace view content_item_globals as select -100 as c_root_folder_id; -select define_function_args('content_item__get_root_folder','item_id'); -create or replace function content_item__get_root_folder (integer) -returns integer as ' -declare - get_root_folder__item_id alias for $1; -- default null + +-- old define_function_args('content_item__get_root_folder','item_id') +-- new +select define_function_args('content_item__get_root_folder','item_id;null'); + + + +-- +-- procedure content_item__get_root_folder/1 +-- +CREATE OR REPLACE FUNCTION content_item__get_root_folder( + get_root_folder__item_id integer -- default null + +) RETURNS integer AS $$ +DECLARE v_folder_id cr_folders.folder_id%TYPE; -begin +BEGIN if get_root_folder__item_id is NULL or get_root_folder__item_id in (-4,-100,-200) then @@ -34,61 +44,52 @@ and i1.tree_sortkey between i2.tree_sortkey and tree_right(i2.tree_sortkey); if NOT FOUND then - raise EXCEPTION '' -20000: Could not find a root folder for item ID %. Either the item does not exist or its parent value is corrupted.'', get_root_folder__item_id; + raise EXCEPTION ' -20000: Could not find a root folder for item ID %. Either the item does not exist or its parent value is corrupted.', get_root_folder__item_id; end if; end if; return v_folder_id; -end;' language 'plpgsql' stable; +END; +$$ LANGUAGE plpgsql stable; -- new 19 param version of content_item__new (now its 20 with package_id) -select define_function_args('content_item__new','name,parent_id,item_id,locale,creation_date;now,creation_user,context_id,creation_ip,item_subtype;content_item,content_type;content_revision,title,description,mime_type;text/plain,nls_language,text,data,relation_tag,is_live;f,storage_type;null,package_id'); -create or replace function content_item__new ( - cr_items.name%TYPE, - cr_items.parent_id%TYPE, - acs_objects.object_id%TYPE, - cr_items.locale%TYPE, - acs_objects.creation_date%TYPE, - acs_objects.creation_user%TYPE, - acs_objects.context_id%TYPE, - acs_objects.creation_ip%TYPE, - acs_object_types.object_type%TYPE, - acs_object_types.object_type%TYPE, - cr_revisions.title%TYPE, - cr_revisions.description%TYPE, - cr_revisions.mime_type%TYPE, - cr_revisions.nls_language%TYPE, - varchar, - cr_revisions.content%TYPE, - cr_child_rels.relation_tag%TYPE, - boolean, - cr_items.storage_type%TYPE, - acs_objects.package_id%TYPE -) returns integer as ' -declare - new__name alias for $1; - new__parent_id alias for $2; -- default null - new__item_id alias for $3; -- default null - new__locale alias for $4; -- default null - new__creation_date alias for $5; -- default now - new__creation_user alias for $6; -- default null - new__context_id alias for $7; -- default null - new__creation_ip alias for $8; -- default null - new__item_subtype alias for $9; -- default ''content_item'' - new__content_type alias for $10; -- default ''content_revision'' - new__title alias for $11; -- default null - new__description alias for $12; -- default null - new__mime_type alias for $13; -- default ''text/plain'' - new__nls_language alias for $14; -- default null - new__text alias for $15; -- default null - new__data alias for $16; -- default null - new__relation_tag alias for $17; -- default null - new__is_live alias for $18; -- default ''f'' - new__storage_type alias for $19; -- default null - new__package_id alias for $20; -- default null +-- old define_function_args('content_item__new','name,parent_id,item_id,locale,creation_date;now,creation_user,context_id,creation_ip,item_subtype;content_item,content_type;content_revision,title,description,mime_type;text/plain,nls_language,text,data,relation_tag,is_live;f,storage_type;null,package_id') +-- new +select define_function_args('content_item__new','name,parent_id;null,item_id;null,locale;null,creation_date;now,creation_user;null,context_id;null,creation_ip;null,item_subtype;content_item,content_type;content_revision,title;null,description;null,mime_type;text/plain,nls_language;null,text;null,data;null,relation_tag;null,is_live;f,storage_type;null,package_id;null'); + + + + +-- +-- procedure content_item__new/20 +-- +CREATE OR REPLACE FUNCTION content_item__new( + new__name cr_items.name%TYPE, + new__parent_id cr_items.parent_id%TYPE, -- default null + new__item_id acs_objects.object_id%TYPE, -- default null + new__locale cr_items.locale%TYPE, -- default null + new__creation_date acs_objects.creation_date%TYPE, -- default now -- default 'now' + new__creation_user acs_objects.creation_user%TYPE, -- default null + new__context_id acs_objects.context_id%TYPE, -- default null + new__creation_ip acs_objects.creation_ip%TYPE, -- default null + new__item_subtype acs_object_types.object_type%TYPE, -- default 'content_item' + new__content_type acs_object_types.object_type%TYPE, -- default 'content_revision' + new__title cr_revisions.title%TYPE, -- default null + new__description cr_revisions.description%TYPE, -- default null + new__mime_type cr_revisions.mime_type%TYPE, -- default 'text/plain' + new__nls_language cr_revisions.nls_language%TYPE, -- default null + new__text varchar, -- default null + new__data cr_revisions.content%TYPE, -- default null + new__relation_tag cr_child_rels.relation_tag%TYPE, -- default null + new__is_live boolean, -- default 'f' + new__storage_type cr_items.storage_type%TYPE, -- default null + new__package_id acs_objects.package_id%TYPE -- default null + +) RETURNS integer AS $$ +DECLARE v_parent_id cr_items.parent_id%TYPE; v_parent_type acs_objects.object_type%TYPE; v_item_id cr_items.item_id%TYPE; @@ -98,7 +99,7 @@ v_rel_tag cr_child_rels.relation_tag%TYPE; v_context_id acs_objects.context_id%TYPE; v_storage_type cr_items.storage_type%TYPE; -begin +BEGIN -- place the item in the context of the pages folder if no -- context specified @@ -117,27 +118,27 @@ end if; -- use the name of the item if no title is supplied - if new__title is null or new__title = '''' then + if new__title is null or new__title = '' then v_title := new__name; else v_title := new__title; end if; if v_parent_id = -4 or - content_folder__is_folder(v_parent_id) = ''t'' then + content_folder__is_folder(v_parent_id) = 't' then if v_parent_id != -4 and content_folder__is_registered( - v_parent_id, new__content_type, ''f'') = ''f'' then + v_parent_id, new__content_type, 'f') = 'f' then - raise EXCEPTION ''-20000: This items content type % is not registered to this folder %'', new__content_type, v_parent_id; + raise EXCEPTION '-20000: This items content type % is not registered to this folder %', new__content_type, v_parent_id; end if; else if v_parent_id != -4 then if new__relation_tag is null then v_rel_tag := content_item__get_content_type(v_parent_id) - || ''-'' || new__content_type; + || '-' || new__content_type; else v_rel_tag := new__relation_tag; end if; @@ -146,13 +147,13 @@ where object_id = v_parent_id; if NOT FOUND then - raise EXCEPTION ''-20000: Invalid parent ID % specified in content_item.new'', v_parent_id; + raise EXCEPTION '-20000: Invalid parent ID % specified in content_item.new', v_parent_id; end if; - if content_item__is_subclass(v_parent_type, ''content_item'') = ''t'' and - content_item__is_valid_child(v_parent_id, new__content_type, v_rel_tag) = ''f'' then + if content_item__is_subclass(v_parent_type, 'content_item') = 't' and + content_item__is_valid_child(v_parent_id, new__content_type, v_rel_tag) = 'f' then - raise EXCEPTION ''-20000: This items content type % is not allowed in this container %'', new__content_type, v_parent_id; + raise EXCEPTION '-20000: This items content type % is not allowed in this container %', new__content_type, v_parent_id; end if; end if; end if; @@ -166,7 +167,7 @@ new__creation_user, new__creation_ip, v_context_id, - ''t'', + 't', v_title, new__package_id ); @@ -180,17 +181,17 @@ -- if the parent is not a folder, insert into cr_child_rels if v_parent_id != -4 and - content_folder__is_folder(v_parent_id) = ''f'' then + content_folder__is_folder(v_parent_id) = 'f' then v_rel_id := acs_object__new( null, - ''cr_item_child_rel'', + 'cr_item_child_rel', now(), null, null, v_parent_id, - ''t'', - v_rel_tag || '': '' || v_parent_id || '' - '' || v_item_id, + 't', + v_rel_tag || ': ' || v_parent_id || ' - ' || v_item_id, new__package_id ); @@ -239,57 +240,47 @@ end if; -- make the revision live if is_live is true - if new__is_live = ''t'' then + if new__is_live = 't' then PERFORM content_item__set_live_revision(v_revision_id); end if; return v_item_id; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create or replace function content_item__new ( - cr_items.name%TYPE, - cr_items.parent_id%TYPE, - acs_objects.object_id%TYPE, - cr_items.locale%TYPE, - acs_objects.creation_date%TYPE, - acs_objects.creation_user%TYPE, - acs_objects.context_id%TYPE, - acs_objects.creation_ip%TYPE, - acs_object_types.object_type%TYPE, - acs_object_types.object_type%TYPE, - cr_revisions.title%TYPE, - cr_revisions.description%TYPE, - cr_revisions.mime_type%TYPE, - cr_revisions.nls_language%TYPE, - varchar, - cr_revisions.content%TYPE, - cr_child_rels.relation_tag%TYPE, - boolean, - cr_items.storage_type%TYPE -) returns integer as ' -declare - new__name alias for $1; - new__parent_id alias for $2; - new__item_id alias for $3; - new__locale alias for $4; - new__creation_date alias for $5; - new__creation_user alias for $6; - new__context_id alias for $7; - new__creation_ip alias for $8; - new__item_subtype alias for $9; - new__content_type alias for $10; - new__title alias for $11; - new__description alias for $12; - new__mime_type alias for $13; - new__nls_language alias for $14; - new__text alias for $15; - new__data alias for $16; - new__relation_tag alias for $17; - new__is_live alias for $18; - new__storage_type alias for $19; + + +-- +-- procedure content_item__new/19 +-- +CREATE OR REPLACE FUNCTION content_item__new( + new__name cr_items.name%TYPE, + new__parent_id cr_items.parent_id%TYPE, + new__item_id acs_objects.object_id%TYPE, + new__locale cr_items.locale%TYPE, + new__creation_date acs_objects.creation_date%TYPE, + new__creation_user acs_objects.creation_user%TYPE, + new__context_id acs_objects.context_id%TYPE, + new__creation_ip acs_objects.creation_ip%TYPE, + new__item_subtype acs_object_types.object_type%TYPE, + new__content_type acs_object_types.object_type%TYPE, + new__title cr_revisions.title%TYPE, + new__description cr_revisions.description%TYPE, + new__mime_type cr_revisions.mime_type%TYPE, + new__nls_language cr_revisions.nls_language%TYPE, + new__text varchar, + new__data cr_revisions.content%TYPE, + new__relation_tag cr_child_rels.relation_tag%TYPE, + new__is_live boolean, + new__storage_type cr_items.storage_type%TYPE +) RETURNS integer AS $$ +-- +-- content_item__new/19 maybe obsolete, when we define proper defaults for /20 +-- +DECLARE v_item_id cr_items.item_id%TYPE; -begin +BEGIN v_item_id := content_item__new (new__name, new__parent_id, new__item_id, new__locale, new__creation_date, new__creation_user, new__context_id, new__creation_ip, new__item_subtype, new__content_type, new__title, new__description, @@ -298,31 +289,41 @@ return v_item_id; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- -create or replace function content_item__new (varchar,integer,integer,varchar,timestamptz,integer,integer,varchar,varchar,varchar,varchar,varchar,varchar,varchar,varchar,varchar,integer) -returns integer as ' -declare - new__name alias for $1; - new__parent_id alias for $2; -- default null - new__item_id alias for $3; -- default null - new__locale alias for $4; -- default null - new__creation_date alias for $5; -- default now() - new__creation_user alias for $6; -- default null - new__context_id alias for $7; -- default null - new__creation_ip alias for $8; -- default null - new__item_subtype alias for $9; -- default ''content_item'' - new__content_type alias for $10; -- default ''content_revision'' - new__title alias for $11; -- default null - new__description alias for $12; -- default null - new__mime_type alias for $13; -- default ''text/plain'' - new__nls_language alias for $14; -- default null - new__text alias for $15; -- default null - new__storage_type alias for $16; -- check in (''text'',''file'') - new__package_id alias for $17; -- default null + + +-- +-- procedure content_item__new/17 +-- +CREATE OR REPLACE FUNCTION content_item__new( + new__name varchar, + new__parent_id integer, -- default null + new__item_id integer, -- default null + new__locale varchar, -- default null + new__creation_date timestamptz, -- default now() + new__creation_user integer, -- default null + new__context_id integer, -- default null + new__creation_ip varchar, -- default null + new__item_subtype varchar, -- default 'content_item' + new__content_type varchar, -- default 'content_revision' + new__title varchar, -- default null + new__description varchar, -- default null + new__mime_type varchar, -- default 'text/plain' + new__nls_language varchar, -- default null + new__text varchar, -- default null + new__storage_type varchar, -- check in ('text','file') + new__package_id integer -- default null + +) RETURNS integer AS $$ +-- +-- content_item__new/17 maybe obsolete, when we define proper defaults for /20 +-- +DECLARE new__relation_tag varchar default null; - new__is_live boolean default ''f''; + new__is_live boolean default 'f'; v_parent_id cr_items.parent_id%TYPE; v_parent_type acs_objects.object_type%TYPE; @@ -332,7 +333,7 @@ v_rel_id acs_objects.object_id%TYPE; v_rel_tag cr_child_rels.relation_tag%TYPE; v_context_id acs_objects.context_id%TYPE; -begin +BEGIN -- place the item in the context of the pages folder if no -- context specified @@ -351,13 +352,13 @@ end if; if v_parent_id = -4 or - content_folder__is_folder(v_parent_id) = ''t'' then + content_folder__is_folder(v_parent_id) = 't' then if v_parent_id != -4 and content_folder__is_registered( - v_parent_id, new__content_type, ''f'') = ''f'' then + v_parent_id, new__content_type, 'f') = 'f' then - raise EXCEPTION ''-20000: This items content type % is not registered to this folder %'', new__content_type, v_parent_id; + raise EXCEPTION '-20000: This items content type % is not registered to this folder %', new__content_type, v_parent_id; end if; else if v_parent_id != -4 then @@ -366,13 +367,13 @@ where object_id = v_parent_id; if NOT FOUND then - raise EXCEPTION ''-20000: Invalid parent ID % specified in content_item.new'', v_parent_id; + raise EXCEPTION '-20000: Invalid parent ID % specified in content_item.new', v_parent_id; end if; - if content_item__is_subclass(v_parent_type, ''content_item'') = ''t'' and - content_item__is_valid_child(v_parent_id, new__content_type) = ''f'' then + if content_item__is_subclass(v_parent_type, 'content_item') = 't' and + content_item__is_valid_child(v_parent_id, new__content_type) = 'f' then - raise EXCEPTION ''-20000: This items content type % is not allowed in this container %'', new__content_type, v_parent_id; + raise EXCEPTION '-20000: This items content type % is not allowed in this container %', new__content_type, v_parent_id; end if; end if; end if; @@ -386,7 +387,7 @@ new__creation_user, new__creation_ip, v_context_id, - ''t'', + 't', coalesce(new__title,new__name), new__package_id ); @@ -399,25 +400,25 @@ -- if the parent is not a folder, insert into cr_child_rels if v_parent_id != -4 and - content_folder__is_folder(v_parent_id) = ''f'' and - content_item__is_valid_child(v_parent_id, new__content_type) = ''t'' then + content_folder__is_folder(v_parent_id) = 'f' and + content_item__is_valid_child(v_parent_id, new__content_type) = 't' then if new__relation_tag is null then v_rel_tag := content_item__get_content_type(v_parent_id) - || ''-'' || new__content_type; + || '-' || new__content_type; else v_rel_tag := new__relation_tag; end if; v_rel_id := acs_object__new( null, - ''cr_item_child_rel'', + 'cr_item_child_rel', now(), null, null, v_parent_id, - ''t'', - v_rel_tag || '': '' || v_parent_id || '' - '' || v_item_id, + 't', + v_rel_tag || ': ' || v_parent_id || ' - ' || v_item_id, new__package_id ); @@ -457,66 +458,86 @@ end if; -- make the revision live if is_live is true - if new__is_live = ''t'' then + if new__is_live = 't' then PERFORM content_item__set_live_revision(v_revision_id); end if; return v_item_id; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create or replace function content_item__new (varchar,integer,integer,varchar,timestamptz,integer,integer,varchar,varchar,varchar,varchar,varchar,varchar,varchar,varchar,varchar) -returns integer as ' -declare - new__name alias for $1; - new__parent_id alias for $2; -- default null - new__item_id alias for $3; -- default null - new__locale alias for $4; -- default null - new__creation_date alias for $5; -- default now() - new__creation_user alias for $6; -- default null - new__context_id alias for $7; -- default null - new__creation_ip alias for $8; -- default null - new__item_subtype alias for $9; -- default ''content_item'' - new__content_type alias for $10; -- default ''content_revision'' - new__title alias for $11; -- default null - new__description alias for $12; -- default null - new__mime_type alias for $13; -- default ''text/plain'' - new__nls_language alias for $14; -- default null - new__text alias for $15; -- default null - new__storage_type alias for $16; -- check in (''text'',''file'') + + +-- +-- procedure content_item__new/16 +-- +CREATE OR REPLACE FUNCTION content_item__new( + new__name varchar, + new__parent_id integer, -- default null + new__item_id integer, -- default null + new__locale varchar, -- default null + new__creation_date timestamptz, -- default now() + new__creation_user integer, -- default null + new__context_id integer, -- default null + new__creation_ip varchar, -- default null + new__item_subtype varchar, -- default 'content_item' + new__content_type varchar, -- default 'content_revision' + new__title varchar, -- default null + new__description varchar, -- default null + new__mime_type varchar, -- default 'text/plain' + new__nls_language varchar, -- default null + new__text varchar, -- default null + new__storage_type varchar -- check in ('text''file') + +) RETURNS integer AS $$ +-- +-- content_item__new/16 maybe obsolete, when we define proper defaults for /20 +-- +DECLARE v_item_id cr_items.item_id%TYPE; -begin +BEGIN v_item_id := content_item__new (new__name, new__parent_id, new__item_id, new__locale, new__creation_date, new__creation_user, new__context_id, new__creation_ip, new__item_subtype, new__content_type, new__title, new__description, new__mime_type, new__nls_language, new__text, new__storage_type, null::integer); return v_item_id; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create or replace function content_item__new (varchar,integer,integer,varchar,timestamptz,integer,integer,varchar,varchar,varchar,varchar,varchar,varchar,varchar,integer,integer) -returns integer as ' -declare - new__name alias for $1; - new__parent_id alias for $2; -- default null - new__item_id alias for $3; -- default null - new__locale alias for $4; -- default null - new__creation_date alias for $5; -- default now() - new__creation_user alias for $6; -- default null - new__context_id alias for $7; -- default null - new__creation_ip alias for $8; -- default null - new__item_subtype alias for $9; -- default ''content_item'' - new__content_type alias for $10; -- default ''content_revision'' - new__title alias for $11; -- default null - new__description alias for $12; -- default null - new__mime_type alias for $13; -- default ''text/plain'' - new__nls_language alias for $14; -- default null + + +-- +-- procedure content_item__new/16 +-- +CREATE OR REPLACE FUNCTION content_item__new( + new__name varchar, + new__parent_id integer, -- default null + new__item_id integer, -- default null + new__locale varchar, -- default null + new__creation_date timestamptz, -- default now() + new__creation_user integer, -- default null + new__context_id integer, -- default null + new__creation_ip varchar, -- default null + new__item_subtype varchar, -- default 'content_item' + new__content_type varchar, -- default 'content_revision' + new__title varchar, -- default null + new__description varchar, -- default null + new__mime_type varchar, -- default 'text/plain' + new__nls_language varchar, -- default null + new__data integer, -- default null + new__package_id integer -- default null + +) RETURNS integer AS $$ +-- +-- content_item__new/16 maybe obsolete, when we define proper defaults for /20 +-- +DECLARE -- changed to integer for blob_id - new__data alias for $15; -- default null - new__package_id alias for $16; -- default null new__relation_tag varchar default null; - new__is_live boolean default ''f''; + new__is_live boolean default 'f'; v_parent_id cr_items.parent_id%TYPE; v_parent_type acs_objects.object_type%TYPE; @@ -526,7 +547,7 @@ v_rel_id acs_objects.object_id%TYPE; v_rel_tag cr_child_rels.relation_tag%TYPE; v_context_id acs_objects.context_id%TYPE; -begin +BEGIN -- place the item in the context of the pages folder if no -- context specified @@ -545,20 +566,20 @@ end if; -- use the name of the item if no title is supplied - if new__title is null or new__title = '''' then + if new__title is null or new__title = '' then v_title := new__name; else v_title := new__title; end if; if v_parent_id = -4 or - content_folder__is_folder(v_parent_id) = ''t'' then + content_folder__is_folder(v_parent_id) = 't' then if v_parent_id != -4 and content_folder__is_registered( - v_parent_id, new__content_type, ''f'') = ''f'' then + v_parent_id, new__content_type, 'f') = 'f' then - raise EXCEPTION ''-20000: This items content type % is not registered to this folder %'', new__content_type, v_parent_id; + raise EXCEPTION '-20000: This items content type % is not registered to this folder %', new__content_type, v_parent_id; end if; else if v_parent_id != -4 then @@ -567,13 +588,13 @@ where object_id = v_parent_id; if NOT FOUND then - raise EXCEPTION ''-20000: Invalid parent ID % specified in content_item.new'', v_parent_id; + raise EXCEPTION '-20000: Invalid parent ID % specified in content_item.new', v_parent_id; end if; - if content_item__is_subclass(v_parent_type, ''content_item'') = ''t'' and - content_item__is_valid_child(v_parent_id, new__content_type) = ''f'' then + if content_item__is_subclass(v_parent_type, 'content_item') = 't' and + content_item__is_valid_child(v_parent_id, new__content_type) = 'f' then - raise EXCEPTION ''-20000: This items content type % is not allowed in this container %'', new__content_type, v_parent_id; + raise EXCEPTION '-20000: This items content type % is not allowed in this container %', new__content_type, v_parent_id; end if; end if; end if; @@ -587,38 +608,38 @@ new__creation_user, new__creation_ip, v_context_id, - ''t'', + 't', v_title, new__package_id ); insert into cr_items ( item_id, name, content_type, parent_id, storage_type ) values ( - v_item_id, new__name, new__content_type, v_parent_id, ''lob'' + v_item_id, new__name, new__content_type, v_parent_id, 'lob' ); -- if the parent is not a folder, insert into cr_child_rels if v_parent_id != -4 and - content_folder__is_folder(v_parent_id) = ''f'' and - content_item__is_valid_child(v_parent_id, new__content_type) = ''t'' then + content_folder__is_folder(v_parent_id) = 'f' and + content_item__is_valid_child(v_parent_id, new__content_type) = 't' then - if new__relation_tag is null or new__relation_tag = '''' then + if new__relation_tag is null or new__relation_tag = '' then v_rel_tag := content_item__get_content_type(v_parent_id) - || ''-'' || new__content_type; + || '-' || new__content_type; else v_rel_tag := new__relation_tag; end if; v_rel_id := acs_object__new( null, - ''cr_item_child_rel'', + 'cr_item_child_rel', now(), null, null, v_parent_id, - ''t'', - v_rel_tag || '': '' || v_parent_id || '' - '' || v_item_id, + 't', + v_rel_tag || ': ' || v_parent_id || ' - ' || v_item_id, new__package_id ); @@ -669,54 +690,74 @@ end if; -- make the revision live if is_live is true - if new__is_live = ''t'' then + if new__is_live = 't' then PERFORM content_item__set_live_revision(v_revision_id); end if; return v_item_id; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create or replace function content_item__new (varchar,integer,integer,varchar,timestamptz,integer,integer,varchar,varchar,varchar,varchar,varchar,varchar,varchar,integer) -returns integer as ' -declare - new__name alias for $1; - new__parent_id alias for $2; -- default null - new__item_id alias for $3; -- default null - new__locale alias for $4; -- default null - new__creation_date alias for $5; -- default now() - new__creation_user alias for $6; -- default null - new__context_id alias for $7; -- default null - new__creation_ip alias for $8; -- default null - new__item_subtype alias for $9; -- default ''content_item'' - new__content_type alias for $10; -- default ''content_revision'' - new__title alias for $11; -- default null - new__description alias for $12; -- default null - new__mime_type alias for $13; -- default ''text/plain'' - new__nls_language alias for $14; -- default null + + +-- +-- procedure content_item__new/15 +-- +CREATE OR REPLACE FUNCTION content_item__new( + new__name varchar, + new__parent_id integer, -- default null + new__item_id integer, -- default null + new__locale varchar, -- default null + new__creation_date timestamptz, -- default now() + new__creation_user integer, -- default null + new__context_id integer, -- default null + new__creation_ip varchar, -- default null + new__item_subtype varchar, -- default 'content_item' + new__content_type varchar, -- default 'content_revision' + new__title varchar, -- default null + new__description varchar, -- default null + new__mime_type varchar, -- default 'text/plain' + new__nls_language varchar, -- default null + new__data integer -- default null + +) RETURNS integer AS $$ +-- +-- content_item__new/15 maybe obsolete, when we define proper defaults for /20 +-- +DECLARE -- changed to integer for blob_id - new__data alias for $15; -- default null v_item_id cr_items.item_id%TYPE; -begin +BEGIN v_item_id := content_item__new (new__name, new__parent_id, new__item_id, new__locale, new__creation_date, new__creation_user, new__context_id, new__creation_ip, new__item_subtype, new__content_type, new__title, new__description, new__mime_type, new__nls_language, new__data, null::integer); return v_item_id; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create or replace function content_item__new(varchar,integer,varchar,text,text,integer) -returns integer as ' -declare - new__name alias for $1; - new__parent_id alias for $2; -- default null - new__title alias for $3; -- default null - new__description alias for $4; -- default null - new__text alias for $5; -- default null - new__package_id alias for $6; -- default null -begin + + +-- +-- procedure content_item__new/6 +-- +CREATE OR REPLACE FUNCTION content_item__new( + new__name varchar, + new__parent_id integer, -- default null + new__title varchar, -- default null + new__description text, -- default null + new__text text, -- default null + new__package_id integer -- default null + +) RETURNS integer AS $$ +-- +-- content_item__new/6 maybe obsolete, when we define proper defaults for /20 +-- +DECLARE +BEGIN return content_item__new(new__name, new__parent_id, null, @@ -725,73 +766,113 @@ null, null, null, - ''content_item'', - ''content_revision'', + 'content_item', + 'content_revision', new__title, new__description, - ''text/plain'', + 'text/plain', null, new__text, - ''text'', + 'text', new__package_id ); -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create or replace function content_item__new(varchar,integer,varchar,text,text) -returns integer as ' -declare - new__name alias for $1; - new__parent_id alias for $2; -- default null - new__title alias for $3; -- default null - new__description alias for $4; -- default null - new__text alias for $5; -- default null -begin + + +-- +-- procedure content_item__new/5 +-- +CREATE OR REPLACE FUNCTION content_item__new( + new__name varchar, + new__parent_id integer, -- default null + new__title varchar, -- default null + new__description text, -- default null + new__text text -- default null + +) RETURNS integer AS $$ +-- +-- content_item__new/5 maybe obsolete, when we define proper defaults for /20 +-- +DECLARE +BEGIN return content_item__new(new__name, new__parent_id, new__title, new__description, new__text, null); -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create or replace function content_item__new(varchar,integer,integer) returns integer as ' -declare - new__name alias for $1; - new__parent_id alias for $2; - new__package_id alias for $3; -begin + + +-- +-- procedure content_item__new/3 +-- +CREATE OR REPLACE FUNCTION content_item__new( + new__name varchar, + new__parent_id integer, + new__package_id integer +) RETURNS integer AS $$ +-- +-- content_item__new/3 maybe obsolete, when we define proper defaults for /20 +-- +DECLARE +BEGIN return content_item__new(new__name, new__parent_id, null, null, null, new__package_id); -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create or replace function content_item__new(varchar,integer) returns integer as ' -declare - new__name alias for $1; - new__parent_id alias for $2; -begin + + +-- +-- procedure content_item__new/2 +-- +CREATE OR REPLACE FUNCTION content_item__new( + new__name varchar, + new__parent_id integer +) RETURNS integer AS $$ +-- +-- content_item__new/2 maybe obsolete, when we define proper defaults for /20 +-- +DECLARE +BEGIN return content_item__new(new__name, new__parent_id, null, null, null, null); -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function new -- sets security_inherit_p to FALSE -DaveB -create or replace function content_item__new ( integer, varchar, integer, varchar, timestamptz, integer, integer, varchar, boolean, varchar, text, varchar, boolean, varchar,varchar,varchar,integer) -returns integer as ' -declare - new__item_id alias for $1; --default null - new__name alias for $2; - new__parent_id alias for $3; -- default null - new__title alias for $4; -- default null - new__creation_date alias for $5; -- default now() - new__creation_user alias for $6; -- default null - new__context_id alias for $7; -- default null - new__creation_ip alias for $8; -- default null - new__is_live alias for $9; -- default ''f'' - new__mime_type alias for $10; - new__text alias for $11; -- default null - new__storage_type alias for $12; -- check in (''text'', ''file'') - new__security_inherit_p alias for $13; -- default ''t'' - new__storage_area_key alias for $14; -- default ''CR_FILES'' - new__item_subtype alias for $15; - new__content_type alias for $16; - new__package_id alias for $17; -- default null + + +-- +-- procedure content_item__new/17 +-- +CREATE OR REPLACE FUNCTION content_item__new( + new__item_id integer, --default null + new__name varchar, + new__parent_id integer, -- default null + new__title varchar, -- default null + new__creation_date timestamptz, -- default now() + new__creation_user integer, -- default null + new__context_id integer, -- default null + new__creation_ip varchar, -- default null + new__is_live boolean, -- default 'f' + new__mime_type varchar, + new__text text, -- default null + new__storage_type varchar, -- check in ('text', 'file') + new__security_inherit_p boolean, -- default 't' + new__storage_area_key varchar, -- default 'CR_FILES' + new__item_subtype varchar, + new__content_type varchar, + new__package_id integer -- default null + +) RETURNS integer AS $$ +-- +-- content_item__new/17 maybe obsolete, when we define proper defaults for /20 +-- +DECLARE new__description varchar default null; new__relation_tag varchar default null; new__nls_language varchar default null; @@ -803,7 +884,7 @@ v_rel_id acs_objects.object_id%TYPE; v_rel_tag cr_child_rels.relation_tag%TYPE; v_context_id acs_objects.context_id%TYPE; -begin +BEGIN -- place the item in the context of the pages folder if no -- context specified @@ -822,20 +903,20 @@ end if; -- use the name of the item if no title is supplied - if new__title is null or new__title = '''' then + if new__title is null or new__title = '' then v_title := new__name; else v_title := new__title; end if; if v_parent_id = -4 or - content_folder__is_folder(v_parent_id) = ''t'' then + content_folder__is_folder(v_parent_id) = 't' then if v_parent_id != -4 and content_folder__is_registered( - v_parent_id, new__content_type, ''f'') = ''f'' then + v_parent_id, new__content_type, 'f') = 'f' then - raise EXCEPTION ''-20000: This items content type % is not registered to this folder %'', new__content_type, v_parent_id; + raise EXCEPTION '-20000: This items content type % is not registered to this folder %', new__content_type, v_parent_id; end if; else if v_parent_id != -4 then @@ -844,13 +925,13 @@ where object_id = v_parent_id; if NOT FOUND then - raise EXCEPTION ''-20000: Invalid parent ID % specified in content_item.new'', v_parent_id; + raise EXCEPTION '-20000: Invalid parent ID % specified in content_item.new', v_parent_id; end if; - if content_item__is_subclass(v_parent_type, ''content_item'') = ''t'' and - content_item__is_valid_child(v_parent_id, new__content_type) = ''f'' then + if content_item__is_subclass(v_parent_type, 'content_item') = 't' and + content_item__is_valid_child(v_parent_id, new__content_type) = 'f' then - raise EXCEPTION ''-20000: This items content type % is not allowed in this container %'', new__content_type, v_parent_id; + raise EXCEPTION '-20000: This items content type % is not allowed in this container %', new__content_type, v_parent_id; end if; end if; end if; @@ -879,25 +960,25 @@ -- if the parent is not a folder, insert into cr_child_rels if v_parent_id != -4 and - content_folder__is_folder(v_parent_id) = ''f'' and - content_item__is_valid_child(v_parent_id, new__content_type) = ''t'' then + content_folder__is_folder(v_parent_id) = 'f' and + content_item__is_valid_child(v_parent_id, new__content_type) = 't' then if new__relation_tag is null then v_rel_tag := content_item__get_content_type(v_parent_id) - || ''-'' || new__content_type; + || '-' || new__content_type; else v_rel_tag := new__relation_tag; end if; v_rel_id := acs_object__new( null, - ''cr_item_child_rel'', + 'cr_item_child_rel', new__creation_date, null, null, v_parent_id, - ''f'', - v_rel_tag || '': '' || v_parent_id || '' - '' || v_item_id, + 'f', + v_rel_tag || ': ' || v_parent_id || ' - ' || v_item_id, new__package_id ); @@ -930,35 +1011,45 @@ end if; -- make the revision live if is_live is true - if new__is_live = ''t'' then + if new__is_live = 't' then PERFORM content_item__set_live_revision(v_revision_id); end if; return v_item_id; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create or replace function content_item__new ( integer, varchar, integer, varchar, timestamptz, integer, integer, varchar, boolean, varchar, text, varchar, boolean, varchar,varchar,varchar) -returns integer as ' -declare - new__item_id alias for $1; --default null - new__name alias for $2; - new__parent_id alias for $3; -- default null - new__title alias for $4; -- default null - new__creation_date alias for $5; -- default now() - new__creation_user alias for $6; -- default null - new__context_id alias for $7; -- default null - new__creation_ip alias for $8; -- default null - new__is_live alias for $9; -- default ''f'' - new__mime_type alias for $10; - new__text alias for $11; -- default null - new__storage_type alias for $12; -- check in (''text'', ''file'') - new__security_inherit_p alias for $13; -- default ''t'' - new__storage_area_key alias for $14; -- default ''CR_FILES'' - new__item_subtype alias for $15; - new__content_type alias for $16; + + +-- +-- procedure content_item__new/16 +-- +CREATE OR REPLACE FUNCTION content_item__new( + new__item_id integer, --default null + new__name varchar, + new__parent_id integer, -- default null + new__title varchar, -- default null + new__creation_date timestamptz, -- default now() + new__creation_user integer, -- default null + new__context_id integer, -- default null + new__creation_ip varchar, -- default null + new__is_live boolean, -- default 'f' + new__mime_type varchar, + new__text text, -- default null + new__storage_type varchar, -- check in ('text', 'file') + new__security_inherit_p boolean, -- default 't' + new__storage_area_key varchar, -- default 'CR_FILES' + new__item_subtype varchar, + new__content_type varchar + +) RETURNS integer AS $$ +-- +-- content_item__new/16 maybe obsolete, when we define proper defaults for /20 +-- +DECLARE v_item_id cr_items.item_id%TYPE; -begin +BEGIN v_item_id := content_item__new (new__item_id, new__name, new__parent_id, new__title, new__creation_date, new__creation_user, new__context_id, new__creation_ip, new__is_live, new__mime_type, new__text, new__storage_type, @@ -967,46 +1058,58 @@ return v_item_id; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select define_function_args('content_item__is_published','item_id'); -create or replace function content_item__is_published (integer) -returns boolean as ' -declare - is_published__item_id alias for $1; -begin + +-- +-- procedure content_item__is_published/1 +-- +CREATE OR REPLACE FUNCTION content_item__is_published( + is_published__item_id integer +) RETURNS boolean AS $$ +DECLARE +BEGIN + return count(*) > 0 from cr_items where live_revision is not null and - publish_status = ''live'' + publish_status = 'live' and item_id = is_published__item_id; -end;' language 'plpgsql' stable; +END; +$$ LANGUAGE plpgsql stable; select define_function_args('content_item__is_publishable','item_id'); -create or replace function content_item__is_publishable (integer) -returns boolean as ' -declare - is_publishable__item_id alias for $1; + + +-- +-- procedure content_item__is_publishable/1 +-- +CREATE OR REPLACE FUNCTION content_item__is_publishable( + is_publishable__item_id integer +) RETURNS boolean AS $$ +DECLARE v_child_count integer; v_rel_count integer; v_content_type varchar; v_template_id cr_templates.template_id%TYPE; v_child_type record; v_rel_type record; -- v_pub_wf record; -begin +BEGIN -- check valid item_id select content_item__get_content_type(is_publishable__item_id) into v_content_type; if v_content_type is null then - raise exception ''content_item__is_publishable item_id % invalid'',is_publishable__item_id; + raise exception 'content_item__is_publishable item_id % invalid',is_publishable__item_id; end if; -- validate children @@ -1031,11 +1134,11 @@ -- make sure # of children is in range if v_child_type.min_n is not null and v_child_count < v_child_type.min_n then - return ''f''; + return 'f'; end if; if v_child_type.max_n is not null and v_child_count > v_child_type.max_n then - return ''f''; + return 'f'; end if; end LOOP; @@ -1065,16 +1168,16 @@ -- make sure # of object relations is in range if v_rel_type.min_n is not null and v_rel_count < v_rel_type.min_n then - return ''f''; + return 'f'; end if; if v_rel_type.max_n is not null and v_rel_count > v_rel_type.max_n then - return ''f''; + return 'f'; end if; end loop; -- validate publishing workflows - -- make sure any ''publishing_wf'' associated with this item are finished + -- make sure any 'publishing_wf' associated with this item are finished -- KG: logic is wrong here. Only the latest workflow matters, and even -- that is a little problematic because more than one workflow may be -- open on an item. In addition, this should be moved to CMS. @@ -1087,38 +1190,44 @@ -- from -- wf_cases -- where - -- workflow_key = ''publishing_wf'' + -- workflow_key = 'publishing_wf' -- and -- object_id = is_publishable__item_id -- -- LOOP - -- if v_pub_wf.state != ''finished'' then - -- return ''f''; + -- if v_pub_wf.state != 'finished' then + -- return 'f'; -- end if; -- end loop; -- if NOT FOUND then - -- return ''f''; + -- return 'f'; -- end if; - return ''t''; + return 't'; -end;' language 'plpgsql' stable; +END; +$$ LANGUAGE plpgsql stable; select define_function_args('content_item__is_valid_child','item_id,content_type,relation_tag'); -create or replace function content_item__is_valid_child (integer,varchar,varchar) -returns boolean as ' -declare - is_valid_child__item_id alias for $1; - is_valid_child__content_type alias for $2; - is_valid_child__relation_tag alias for $3; + + +-- +-- procedure content_item__is_valid_child/3 +-- +CREATE OR REPLACE FUNCTION content_item__is_valid_child( + is_valid_child__item_id integer, + is_valid_child__content_type varchar, + is_valid_child__relation_tag varchar +) RETURNS boolean AS $$ +DECLARE v_is_valid_child boolean; v_max_children cr_type_children.max_n%TYPE; v_n_children integer; v_null_exists boolean; -begin +BEGIN - v_is_valid_child := ''f''; + v_is_valid_child := 'f'; -- first check if content_type is a registered child_type select @@ -1134,12 +1243,12 @@ or is_valid_child__relation_tag = relation_tag); if NOT FOUND then - return ''f''; + return 'f'; end if; -- if the max is null then infinite number is allowed if v_max_children is null then - return ''t''; + return 't'; end if; -- next check if there are already max_n children of that content type @@ -1156,29 +1265,38 @@ or is_valid_child__relation_tag = relation_tag); if NOT FOUND then - return ''f''; + return 'f'; end if; if v_n_children < v_max_children then - v_is_valid_child := ''t''; + v_is_valid_child := 't'; end if; return v_is_valid_child; -end;' language 'plpgsql' stable; +END; +$$ LANGUAGE plpgsql stable; -create or replace function content_item__is_valid_child (integer,varchar) -returns boolean as ' -declare - is_valid_child__item_id alias for $1; - is_valid_child__content_type alias for $2; + + +-- +-- procedure content_item__is_valid_child/2 +-- +CREATE OR REPLACE FUNCTION content_item__is_valid_child( + is_valid_child__item_id integer, + is_valid_child__content_type varchar +) RETURNS boolean AS $$ +-- +-- content_item__is_valid_child/2 maybe obsolete, when we define proper defaults for /3 +-- +DECLARE v_is_valid_child boolean; v_max_children cr_type_children.max_n%TYPE; v_n_children integer; -begin +BEGIN - v_is_valid_child := ''f''; + v_is_valid_child := 'f'; -- first check if content_type is a registered child_type select @@ -1191,12 +1309,12 @@ child_type = is_valid_child__content_type; if NOT FOUND then - return ''f''; + return 'f'; end if; -- if the max is null then infinite number is allowed if v_max_children is null then - return ''t''; + return 't'; end if; -- next check if there are already max_n children of that content type @@ -1210,16 +1328,17 @@ content_item__get_content_type(child_id) = is_valid_child__content_type; if NOT FOUND then - return ''f''; + return 'f'; end if; if v_n_children < v_max_children then - v_is_valid_child := ''t''; + v_is_valid_child := 't'; end if; return v_is_valid_child; -end;' language 'plpgsql' stable; +END; +$$ LANGUAGE plpgsql stable; /* delete a content item @@ -1232,20 +1351,25 @@ 7) delete all associated comments */ select define_function_args('content_item__del','item_id'); -create or replace function content_item__del (integer) -returns integer as ' -declare - delete__item_id alias for $1; + + +-- +-- procedure content_item__del/1 +-- +CREATE OR REPLACE FUNCTION content_item__del( + delete__item_id integer +) RETURNS integer AS $$ +DECLARE -- v_wf_cases_val record; v_symlink_val record; v_revision_val record; v_rel_val record; -begin +BEGIN -- Removed this as having workflow stuff in the CR is just plain wrong. -- DanW, Aug 25th, 2001. - -- raise NOTICE ''Deleting associated workflows...''; + -- raise NOTICE 'Deleting associated workflows...'; -- 1) delete all workflow cases associated with this item -- for v_wf_cases_val in select -- case_id @@ -1344,26 +1468,38 @@ PERFORM acs_object__delete(delete__item_id); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select define_function_args('content_item__delete','item_id'); -create or replace function content_item__delete (integer) -returns integer as ' -declare - delete__item_id alias for $1; -begin + + +-- +-- procedure content_item__delete/1 +-- +CREATE OR REPLACE FUNCTION content_item__delete( + delete__item_id integer +) RETURNS integer AS $$ +DECLARE +BEGIN PERFORM content_item__del (delete__item_id); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select define_function_args('content_item__edit_name','item_id,name'); -create or replace function content_item__edit_name (integer,varchar) -returns integer as ' -declare - edit_name__item_id alias for $1; - edit_name__name alias for $2; + + +-- +-- procedure content_item__edit_name/2 +-- +CREATE OR REPLACE FUNCTION content_item__edit_name( + edit_name__item_id integer, + edit_name__name varchar +) RETURNS integer AS $$ +DECLARE exists_id integer; -begin +BEGIN select item_id into @@ -1389,21 +1525,32 @@ where object_id = edit_name__item_id; else if exists_id != edit_name__item_id then - raise EXCEPTION ''-20000: An item with the name % already exists in this directory.'', edit_name__name; + raise EXCEPTION '-20000: An item with the name % already exists in this directory.', edit_name__name; end if; end if; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -select define_function_args('content_item__get_id','item_path,root_folder_id,resolve_index;f'); -create or replace function content_item__get_id (varchar,integer,boolean) -returns integer as ' -declare - get_id__item_path alias for $1; - get_id__root_folder_id alias for $2; -- default null - get_id__resolve_index alias for $3; -- default ''f'' +-- old define_function_args('content_item__get_id','item_path,root_folder_id,resolve_index;f') +-- new +select define_function_args('content_item__get_id','item_path,root_folder_id;null,resolve_index;f'); + + + + +-- +-- procedure content_item__get_id/3 +-- +CREATE OR REPLACE FUNCTION content_item__get_id( + get_id__item_path varchar, + get_id__root_folder_id integer, -- default null + get_id__resolve_index boolean -- default 'f' + +) RETURNS integer AS $$ +DECLARE v_item_path varchar; v_root_folder_id cr_items.item_id%TYPE; get_id__parent_id integer; @@ -1412,7 +1559,7 @@ end_pos integer; counter integer default 1; item_name varchar; -begin +BEGIN if get_id__root_folder_id is null then select c_root_folder_id from content_item_globals into v_root_folder_id; @@ -1421,12 +1568,12 @@ end if; -- If the request path is the root, then just return the root folder - if get_id__item_path = ''/'' then + if get_id__item_path = '/' then return v_root_folder_id; end if; -- Remove leading, trailing spaces, leading slashes - v_item_path := rtrim(ltrim(trim(get_id__item_path), ''/''), ''/''); + v_item_path := rtrim(ltrim(trim(get_id__item_path), '/'), '/'); get_id__parent_id := v_root_folder_id; @@ -1435,7 +1582,7 @@ LOOP - end_pos := instr(v_item_path, ''/'', 1, counter); + end_pos := instr(v_item_path, '/', 1, counter); if end_pos = 0 then item_name := substr(v_item_path, start_pos); @@ -1468,11 +1615,11 @@ end loop; - if get_id__resolve_index = ''t'' then + if get_id__resolve_index = 't' then -- if the item is a folder and has an index page, then return - if content_folder__is_folder(child_id ) = ''t'' and + if content_folder__is_folder(child_id ) = 't' and content_folder__get_index_page(child_id) is not null then child_id := content_folder__get_index_page(child_id); @@ -1482,7 +1629,8 @@ return child_id; -end;' language 'plpgsql' stable; +END; +$$ LANGUAGE plpgsql stable; -- create sequence content_item_gp_session_id; @@ -1750,23 +1898,33 @@ -- end;' language 'plpgsql'; -select define_function_args('content_item__get_path','item_id,root_folder_id'); -create or replace function content_item__get_path (integer,integer) -returns varchar as ' -declare - get_path__item_id alias for $1; - get_path__root_folder_id alias for $2; -- default null + +-- old define_function_args('content_item__get_path','item_id,root_folder_id') +-- new +select define_function_args('content_item__get_path','item_id,root_folder_id;null'); + + + +-- +-- procedure content_item__get_path/2 +-- +CREATE OR REPLACE FUNCTION content_item__get_path( + get_path__item_id integer, + get_path__root_folder_id integer -- default null + +) RETURNS varchar AS $$ +DECLARE v_count integer; v_resolved_root_id integer; - v_path text default ''''; + v_path text default ''; v_rec record; -begin +BEGIN -- check that the item exists select count(*) into v_count from cr_items where item_id = get_path__item_id; if v_count = 0 then - raise EXCEPTION ''-20000: Invalid item ID: %'', get_path__item_id; + raise EXCEPTION '-20000: Invalid item ID: %', get_path__item_id; end if; -- begin walking down the path to the item (from the repository root) @@ -1797,7 +1955,7 @@ and not tree_ancestor_p(i2.tree_sortkey, i3.tree_sortkey) order by tree_level desc LOOP - v_path := v_path || ''../''; + v_path := v_path || '../'; end loop; -- lets now assign the new root_id to be the last parent_id on the loop v_resolved_root_id := v_rec.parent_id; @@ -1816,13 +1974,13 @@ v_path := v_path || v_rec.name; if v_rec.item_id <> get_path__item_id then -- put a / if we are still going down - v_path := v_path || ''/''; + v_path := v_path || '/'; end if; end loop; else - -- this is an absolute path so prepend a ''/'' + -- this is an absolute path so prepend a '/' -- loop over the absolute path for v_rec in select i2.name, tree_level(i2.tree_sortkey) as tree_level @@ -1832,28 +1990,35 @@ and i1.tree_sortkey between i2.tree_sortkey and tree_right(i2.tree_sortkey) order by tree_level LOOP - v_path := v_path || ''/'' || v_rec.name; + v_path := v_path || '/' || v_rec.name; end loop; end if; return v_path; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- I hard code the content_item_globals.c_root_folder_id here select define_function_args('content_item__get_virtual_path','item_id,root_folder_id;-100'); -create or replace function content_item__get_virtual_path (integer,integer) -returns varchar as ' -declare - get_virtual_path__item_id alias for $1; - get_virtual_path__root_folder_id alias for $2; -- default content_item_globals.c_root_folder_id + + +-- +-- procedure content_item__get_virtual_path/2 +-- +CREATE OR REPLACE FUNCTION content_item__get_virtual_path( + get_virtual_path__item_id integer, + get_virtual_path__root_folder_id integer -- default content_item_globals.c_root_folder_id -- default '-100' + +) RETURNS varchar AS $$ +DECLARE v_path varchar; v_item_id cr_items.item_id%TYPE; v_is_folder boolean; v_index cr_items.item_id%TYPE; -begin +BEGIN -- XXX possible bug: root_folder_id arg is ignored. -- first resolve the item @@ -1863,52 +2028,67 @@ v_index := content_folder__get_index_page(v_item_id); -- if the folder has an index page - if v_is_folder = ''t'' and v_index is not null then + if v_is_folder = 't' and v_index is not null then v_path := content_item__get_path(content_symlink__resolve(v_index),null); else v_path := content_item__get_path(v_item_id,null); end if; return v_path; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create or replace function content_item__write_to_file (integer,varchar) -returns integer as ' -declare - item_id alias for $1; - root_path alias for $2; + + +-- added +select define_function_args('content_item__write_to_file','item_id,root_path'); + +-- +-- procedure content_item__write_to_file/2 +-- +CREATE OR REPLACE FUNCTION content_item__write_to_file( + item_id integer, + root_path varchar +) RETURNS integer AS $$ +DECLARE -- blob_loc cr_revisions.content%TYPE; -- v_revision cr_items.live_revision%TYPE; -begin +BEGIN -- FIXME: - raise NOTICE ''not implemented for postgresql''; + raise NOTICE 'not implemented for postgresql'; /* v_revision := content_item__get_live_revision(item_id); select content into blob_loc from cr_revisions where revision_id = v_revision; if NOT FOUND then - raise EXCEPTION ''-20000: No live revision for content item % in content_item.write_to_file.'', item_id; + raise EXCEPTION '-20000: No live revision for content item % in content_item.write_to_file.', item_id; end if; PERFORM blob_to_file(root_path || content_item__get_path(item_id), blob_loc); */ return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select define_function_args('content_item__register_template','item_id,template_id,use_context'); -create or replace function content_item__register_template (integer,integer,varchar) -returns integer as ' -declare - register_template__item_id alias for $1; - register_template__template_id alias for $2; - register_template__use_context alias for $3; + + +-- +-- procedure content_item__register_template/3 +-- +CREATE OR REPLACE FUNCTION content_item__register_template( + register_template__item_id integer, + register_template__template_id integer, + register_template__use_context varchar +) RETURNS integer AS $$ +DECLARE -begin +BEGIN -- register template if it is not already registered insert into cr_item_template_map @@ -1930,18 +2110,29 @@ use_context = register_template__use_context ); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -select define_function_args('content_item__unregister_template','item_id,template_id,use_context'); -create or replace function content_item__unregister_template (integer,integer,varchar) -returns integer as ' -declare - unregister_template__item_id alias for $1; - unregister_template__template_id alias for $2; -- default null - unregister_template__use_context alias for $3; -- default null + +-- old define_function_args('content_item__unregister_template','item_id,template_id,use_context') +-- new +select define_function_args('content_item__unregister_template','item_id,template_id;null,use_context;null'); + + + +-- +-- procedure content_item__unregister_template/3 +-- +CREATE OR REPLACE FUNCTION content_item__unregister_template( + unregister_template__item_id integer, + unregister_template__template_id integer, -- default null + unregister_template__use_context varchar -- default null + +) RETURNS integer AS $$ +DECLARE -begin +BEGIN if unregister_template__use_context is null and unregister_template__template_id is null then @@ -1971,18 +2162,24 @@ end if; end if; end if; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select define_function_args('content_item__get_template','item_id,use_context'); -create or replace function content_item__get_template (integer,varchar) -returns integer as ' -declare - get_template__item_id alias for $1; - get_template__use_context alias for $2; + + +-- +-- procedure content_item__get_template/2 +-- +CREATE OR REPLACE FUNCTION content_item__get_template( + get_template__item_id integer, + get_template__use_context varchar +) RETURNS integer AS $$ +DECLARE v_template_id cr_templates.template_id%TYPE; v_content_type cr_items.content_type%TYPE; -begin +BEGIN -- look for a template assigned specifically to this item select @@ -2010,7 +2207,7 @@ and m.use_context = get_template__use_context and - m.is_default = ''t''; + m.is_default = 't'; if NOT FOUND then return null; @@ -2019,15 +2216,21 @@ return v_template_id; -end;' language 'plpgsql' stable strict; +END; +$$ LANGUAGE plpgsql stable strict; select define_function_args('content_item__get_content_type','item_id'); -create or replace function content_item__get_content_type (integer) -returns varchar as ' -declare - get_content_type__item_id alias for $1; + + +-- +-- procedure content_item__get_content_type/1 +-- +CREATE OR REPLACE FUNCTION content_item__get_content_type( + get_content_type__item_id integer +) RETURNS varchar AS $$ +DECLARE v_content_type cr_items.content_type%TYPE; -begin +BEGIN select content_type into v_content_type @@ -2038,18 +2241,24 @@ return v_content_type; -end;' language 'plpgsql' stable strict; +END; +$$ LANGUAGE plpgsql stable strict; select define_function_args('content_item__get_live_revision','item_id'); select define_function_args('content_item__get_live_revision','item_id'); -create or replace function content_item__get_live_revision (integer) -returns integer as ' -declare - get_live_revision__item_id alias for $1; + + +-- +-- procedure content_item__get_live_revision/1 +-- +CREATE OR REPLACE FUNCTION content_item__get_live_revision( + get_live_revision__item_id integer +) RETURNS integer AS $$ +DECLARE v_revision_id acs_objects.object_id%TYPE; -begin +BEGIN select live_revision into v_revision_id @@ -2060,15 +2269,25 @@ return v_revision_id; -end;' language 'plpgsql' stable strict; +END; +$$ LANGUAGE plpgsql stable strict; select define_function_args('content_item__set_live_revision','revision_id,publish_status;ready'); -create or replace function content_item__set_live_revision (integer) returns integer as ' -declare - set_live_revision__revision_id alias for $1; - set_live_revision__publish_status cr_items.publish_status%TYPE default ''ready''; -begin + +-- +-- procedure content_item__set_live_revision/1 +-- +CREATE OR REPLACE FUNCTION content_item__set_live_revision( + set_live_revision__revision_id integer +) RETURNS integer AS $$ +-- +-- content_item__set_live_revision/1 maybe obsolete, when we define proper defaults for /2 +-- +DECLARE + set_live_revision__publish_status cr_items.publish_status%TYPE default 'ready'; +BEGIN + update cr_items set @@ -2090,16 +2309,23 @@ revision_id = set_live_revision__revision_id; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select define_function_args('content_item__set_live_revision','revision_id,publish_status;ready'); -create or replace function content_item__set_live_revision (integer,varchar) -returns integer as ' -declare - set_live_revision__revision_id alias for $1; - set_live_revision__publish_status alias for $2; -- default ''ready'' -begin + +-- +-- procedure content_item__set_live_revision/2 +-- +CREATE OR REPLACE FUNCTION content_item__set_live_revision( + set_live_revision__revision_id integer, + set_live_revision__publish_status varchar -- default 'ready' + +) RETURNS integer AS $$ +DECLARE +BEGIN + update cr_items set @@ -2121,15 +2347,21 @@ revision_id = set_live_revision__revision_id; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select define_function_args('content_item__unset_live_revision','item_id'); -create or replace function content_item__unset_live_revision (integer) -returns integer as ' -declare - unset_live_revision__item_id alias for $1; -begin + +-- +-- procedure content_item__unset_live_revision/1 +-- +CREATE OR REPLACE FUNCTION content_item__unset_live_revision( + unset_live_revision__item_id integer +) RETURNS integer AS $$ +DECLARE +BEGIN + update cr_items set @@ -2141,25 +2373,36 @@ update cr_items set - publish_status = ''production'' + publish_status = 'production' where - publish_status = ''live'' + publish_status = 'live' and item_id = unset_live_revision__item_id; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -select define_function_args('content_item__set_release_period','item_id,start_when,end_when'); -create or replace function content_item__set_release_period (integer, timestamptz, timestamptz) -returns integer as ' -declare - set_release_period__item_id alias for $1; - set_release_period__start_when alias for $2; -- default null - set_release_period__end_when alias for $3; -- default null +-- old define_function_args('content_item__set_release_period','item_id,start_when,end_when') +-- new +select define_function_args('content_item__set_release_period','item_id,start_when;null,end_when;null'); + + + + +-- +-- procedure content_item__set_release_period/3 +-- +CREATE OR REPLACE FUNCTION content_item__set_release_period( + set_release_period__item_id integer, + set_release_period__start_when timestamptz, -- default null + set_release_period__end_when timestamptz -- default null + +) RETURNS integer AS $$ +DECLARE v_count integer; -begin +BEGIN select count(*) into v_count from cr_release_periods where item_id = set_release_period__item_id; @@ -2181,18 +2424,24 @@ end if; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select define_function_args('content_item__get_revision_count','item_id'); select define_function_args('content_item__get_revision_count','item_id'); -create or replace function content_item__get_revision_count (integer) -returns integer as ' -declare - get_revision_count__item_id alias for $1; + + +-- +-- procedure content_item__get_revision_count/1 +-- +CREATE OR REPLACE FUNCTION content_item__get_revision_count( + get_revision_count__item_id integer +) RETURNS integer AS $$ +DECLARE v_count integer; -begin +BEGIN select count(*) into v_count @@ -2203,15 +2452,21 @@ return v_count; -end;' language 'plpgsql' stable; +END; +$$ LANGUAGE plpgsql stable; select define_function_args('content_item__get_context','item_id'); -create or replace function content_item__get_context (integer) -returns integer as ' -declare - get_context__item_id alias for $1; + + +-- +-- procedure content_item__get_context/1 +-- +CREATE OR REPLACE FUNCTION content_item__get_context( + get_context__item_id integer +) RETURNS integer AS $$ +DECLARE v_context_id acs_objects.context_id%TYPE; -begin +BEGIN select context_id @@ -2223,57 +2478,72 @@ object_id = get_context__item_id; if NOT FOUND then - raise EXCEPTION ''-20000: Content item % does not exist in content_item.get_context'', get_context__item_id; + raise EXCEPTION '-20000: Content item % does not exist in content_item.get_context', get_context__item_id; end if; return v_context_id; -end;' language 'plpgsql' stable; +END; +$$ LANGUAGE plpgsql stable; -- 1) make sure we are not moving the item to an invalid location: -- that is, the destination folder exists and is a valid folder -- 2) make sure the content type of the content item is registered -- to the target folder -- 3) update the parent_id for the item -create or replace function content_item__move (integer,integer) -returns integer as ' -declare - move__item_id alias for $1; - move__target_folder_id alias for $2; -begin + + +-- +-- procedure content_item__move/2 +-- +CREATE OR REPLACE FUNCTION content_item__move( + move__item_id integer, + move__target_folder_id integer +) RETURNS integer AS $$ +-- +-- content_item__move/2 maybe obsolete, when we define proper defaults for /3 +-- +DECLARE +BEGIN perform content_item__move( move__item_id, move__target_folder_id, NULL ); return null; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select define_function_args('content_item__move','item_id,target_folder_id,name'); -create or replace function content_item__move (integer,integer,varchar) -returns integer as ' -declare - move__item_id alias for $1; - move__target_folder_id alias for $2; - move__name alias for $3; -begin + +-- +-- procedure content_item__move/3 +-- +CREATE OR REPLACE FUNCTION content_item__move( + move__item_id integer, + move__target_folder_id integer, + move__name varchar +) RETURNS integer AS $$ +DECLARE +BEGIN + if move__target_folder_id is null then - raise exception ''attempt to move item_id % to null folder_id'', move__item_id; + raise exception 'attempt to move item_id % to null folder_id', move__item_id; end if; - if content_folder__is_folder(move__item_id) = ''t'' then + if content_folder__is_folder(move__item_id) = 't' then PERFORM content_folder__move(move__item_id, move__target_folder_id); - elsif content_folder__is_folder(move__target_folder_id) = ''t'' then + elsif content_folder__is_folder(move__target_folder_id) = 't' then if content_folder__is_registered(move__target_folder_id, - content_item__get_content_type(move__item_id),''f'') = ''t'' and + content_item__get_content_type(move__item_id),'f') = 't' and content_folder__is_registered(move__target_folder_id, - content_item__get_content_type(content_symlink__resolve(move__item_id)),''f'') = ''t'' + content_item__get_content_type(content_symlink__resolve(move__item_id)),'f') = 't' then -- update the parent_id for the item @@ -2292,23 +2562,86 @@ end if; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; +select define_function_args('content_item__generic_move','item_id,target_item_id,name'); -create or replace function content_item__copy (integer,integer,integer,varchar) -returns integer as ' -declare - item_id alias for $1; - target_folder_id alias for $2; - creation_user alias for $3; - creation_ip alias for $4; -- default null + +-- +-- procedure content_item__generic_move/3 +-- +CREATE OR REPLACE FUNCTION content_item__generic_move( + move__item_id integer, + move__target_item_id integer, + move__name varchar +) RETURNS integer AS $$ +DECLARE +BEGIN + + if move__target_item_id is null then + raise exception 'attempt to move item_id % to null folder_id', move__item_id; + end if; + + if content_folder__is_folder(move__item_id) = 't' then + + PERFORM content_folder__move(move__item_id, move__target_item_id); + + elsif content_folder__is_folder(move__target_item_id) = 't' then + + if content_folder__is_registered(move__target_item_id, + content_item__get_content_type(move__item_id),'f') = 't' and + content_folder__is_registered(move__target_item_id, + content_item__get_content_type(content_symlink__resolve(move__item_id)),'f') = 't' + then + end if; + end if; + + -- update the parent_id for the item + + update cr_items + set parent_id = move__target_item_id, + name = coalesce(move__name, name) + where item_id = move__item_id; + + -- GN: the following "end if" appears to be not needed + -- end if; + + if move__name is not null then + update acs_objects + set title = move__name + where object_id = move__item_id; + end if; + + return 0; +END; +$$ LANGUAGE plpgsql; + + + + +-- +-- procedure content_item__copy/4 +-- +CREATE OR REPLACE FUNCTION content_item__copy( + item_id integer, + target_folder_id integer, + creation_user integer, + creation_ip varchar -- default null + +) RETURNS integer AS $$ +-- +-- content_item__copy/4 maybe obsolete, when we define proper defaults for /5 +-- +DECLARE copy_id cr_items.item_id%TYPE; -begin +BEGIN copy_id := content_item__copy2(item_id, target_folder_id, creation_user, creation_ip); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- copy a content item to a target folder -- 1) make sure we are not copying the item to an invalid location: @@ -2319,15 +2652,24 @@ -- 3) create a new item with no revisions in the target folder -- 4) copy the latest revision from the original item to the new item (if any) -create or replace function content_item__copy2 (integer,integer,integer,varchar) -returns integer as ' -declare - copy2__item_id alias for $1; - copy2__target_folder_id alias for $2; - copy2__creation_user alias for $3; - copy2__creation_ip alias for $4; -- default null -begin + +-- added +select define_function_args('content_item__copy2','item_id,target_folder_id,creation_user,creation_ip;null'); + +-- +-- procedure content_item__copy2/4 +-- +CREATE OR REPLACE FUNCTION content_item__copy2( + copy2__item_id integer, + copy2__target_folder_id integer, + copy2__creation_user integer, + copy2__creation_ip varchar -- default null + +) RETURNS integer AS $$ +DECLARE +BEGIN + perform content_item__copy ( copy2__item_id, copy2__target_folder_id, @@ -2337,22 +2679,28 @@ ); return copy2__item_id; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -select define_function_args('content_item__copy','item_id,target_folder_id,creation_user,creation_ip,name'); -create or replace function content_item__copy ( - integer, - integer, - integer, - varchar, - varchar -) returns integer as ' -declare - copy__item_id alias for $1; - copy__target_folder_id alias for $2; - copy__creation_user alias for $3; - copy__creation_ip alias for $4; -- default null - copy__name alias for $5; -- default null + +-- old define_function_args('content_item__copy','item_id,target_folder_id,creation_user,creation_ip,name') +-- new +select define_function_args('content_item__copy','item_id,target_folder_id,creation_user,creation_ip;null,name;null'); + + + +-- +-- procedure content_item__copy/5 +-- +CREATE OR REPLACE FUNCTION content_item__copy( + copy__item_id integer, + copy__target_folder_id integer, + copy__creation_user integer, + copy__creation_ip varchar, -- default null + copy__name varchar -- default null + +) RETURNS integer AS $$ +DECLARE v_current_folder_id cr_folders.folder_id%TYPE; v_num_revisions integer; v_name cr_items.name%TYPE; @@ -2366,10 +2714,10 @@ v_old_live_revision_id cr_revisions.revision_id%TYPE; v_new_live_revision_id cr_revisions.revision_id%TYPE; v_storage_type cr_items.storage_type%TYPE; -begin +BEGIN -- call content_folder.copy if the item is a folder - if content_folder__is_folder(copy__item_id) = ''t'' then + if content_folder__is_folder(copy__item_id) = 't' then PERFORM content_folder__copy( copy__item_id, copy__target_folder_id, @@ -2379,7 +2727,7 @@ ); -- call content_symlink.copy if the item is a symlink - else if content_symlink__is_symlink(copy__item_id) = ''t'' then + else if content_symlink__is_symlink(copy__item_id) = 't' then PERFORM content_symlink__copy( copy__item_id, copy__target_folder_id, @@ -2389,7 +2737,7 @@ ); -- call content_extlink.copy if the item is an url - else if content_extlink__is_extlink(copy__item_id) = ''t'' then + else if content_extlink__is_extlink(copy__item_id) = 't' then PERFORM content_extlink__copy( copy__item_id, copy__target_folder_id, @@ -2399,7 +2747,7 @@ ); -- make sure the target folder is really a folder - else if content_folder__is_folder(copy__target_folder_id) = ''t'' then + else if content_folder__is_folder(copy__target_folder_id) = 't' then select parent_id @@ -2428,10 +2776,10 @@ v_is_registered := content_folder__is_registered( copy__target_folder_id, v_content_type, - ''f'' + 'f' ); - if v_is_registered = ''t'' then + if v_is_registered = 't' then -- create the new content item v_item_id := content_item__new( coalesce (copy__name, v_name), @@ -2442,11 +2790,11 @@ copy__creation_user, null, copy__creation_ip, - ''content_item'', + 'content_item', v_content_type, null, null, - ''text/plain'', + 'text/plain', null, null, v_storage_type @@ -2494,18 +2842,24 @@ return v_item_id; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select define_function_args('content_item__get_latest_revision','item_id'); -create or replace function content_item__get_latest_revision (integer) -returns integer as ' -declare - get_latest_revision__item_id alias for $1; + + +-- +-- procedure content_item__get_latest_revision/1 +-- +CREATE OR REPLACE FUNCTION content_item__get_latest_revision( + get_latest_revision__item_id integer +) RETURNS integer AS $$ +DECLARE v_revision_id integer; v_rec record; -begin +BEGIN for v_rec in select r.revision_id @@ -2524,15 +2878,21 @@ return v_revision_id; -end;' language 'plpgsql' strict stable; +END; +$$ LANGUAGE plpgsql strict stable; select define_function_args('content_item__get_best_revision','item_id'); -create or replace function content_item__get_best_revision (integer) -returns integer as ' -declare - get_best_revision__item_id alias for $1; + + +-- +-- procedure content_item__get_best_revision/1 +-- +CREATE OR REPLACE FUNCTION content_item__get_best_revision( + get_best_revision__item_id integer +) RETURNS integer AS $$ +DECLARE v_revision_id cr_revisions.revision_id%TYPE; -begin +BEGIN select coalesce(live_revision, latest_revision ) @@ -2545,28 +2905,35 @@ return v_revision_id; -end;' language 'plpgsql' stable strict; +END; +$$ LANGUAGE plpgsql stable strict; select define_function_args('content_item__get_title','item_id,is_live;f'); -create or replace function content_item__get_title (integer,boolean) -returns varchar as ' -declare - get_title__item_id alias for $1; - get_title__is_live alias for $2; -- default ''f'' + + +-- +-- procedure content_item__get_title/2 +-- +CREATE OR REPLACE FUNCTION content_item__get_title( + get_title__item_id integer, + get_title__is_live boolean -- default 'f' + +) RETURNS varchar AS $$ +DECLARE v_title cr_revisions.title%TYPE; v_content_type cr_items.content_type%TYPE; -begin +BEGIN select content_type into v_content_type from cr_items where item_id = get_title__item_id; - if v_content_type = ''content_folder'' then + if v_content_type = 'content_folder' then select label into v_title from cr_folders where folder_id = get_title__item_id; - else if v_content_type = ''content_symlink'' then + else if v_content_type = 'content_symlink' then select label into v_title from cr_symlinks where symlink_id = get_title__item_id; - else if v_content_type = ''content_extlink'' then + else if v_content_type = 'content_extlink' then select label into v_title from cr_extlinks where extlink_id = get_title__item_id; else @@ -2593,28 +2960,44 @@ return v_title; -end;' language 'plpgsql' stable; +END; +$$ LANGUAGE plpgsql stable; -create or replace function content_item__get_title (integer) -returns varchar as ' -declare - get_title__item_id alias for $1; -begin + + +-- +-- procedure content_item__get_title/1 +-- +CREATE OR REPLACE FUNCTION content_item__get_title( + get_title__item_id integer +) RETURNS varchar AS $$ +-- +-- content_item__get_title/1 maybe obsolete, when we define proper defaults for /2 +-- +DECLARE +BEGIN - return content_item__get_title(get_title__item_id, ''f''); + return content_item__get_title(get_title__item_id, 'f'); -end;' language 'plpgsql' stable strict; +END; +$$ LANGUAGE plpgsql stable strict; select define_function_args('content_item__get_publish_date','item_id,is_live;f'); -create or replace function content_item__get_publish_date (integer,boolean) -returns timestamptz as ' -declare - get_publish_date__item_id alias for $1; - get_publish_date__is_live alias for $2; -- default ''f'' + + +-- +-- procedure content_item__get_publish_date/2 +-- +CREATE OR REPLACE FUNCTION content_item__get_publish_date( + get_publish_date__item_id integer, + get_publish_date__is_live boolean -- default 'f' + +) RETURNS timestamptz AS $$ +DECLARE v_revision_id cr_revisions.revision_id%TYPE; v_publish_date cr_revisions.publish_date%TYPE; -begin +BEGIN if get_publish_date__is_live then select @@ -2638,17 +3021,23 @@ return v_publish_date; -end;' language 'plpgsql' stable; +END; +$$ LANGUAGE plpgsql stable; select define_function_args('content_item__is_subclass','object_type,supertype'); -create or replace function content_item__is_subclass (varchar,varchar) -returns boolean as ' -declare - is_subclass__object_type alias for $1; - is_subclass__supertype alias for $2; + + +-- +-- procedure content_item__is_subclass/2 +-- +CREATE OR REPLACE FUNCTION content_item__is_subclass( + is_subclass__object_type varchar, + is_subclass__supertype varchar +) RETURNS boolean AS $$ +DECLARE v_subclass_p boolean; v_inherit_val record; -begin +BEGIN select count(*) > 0 into v_subclass_p where exists ( select 1 from acs_object_types o, acs_object_types o2 @@ -2658,25 +3047,36 @@ return v_subclass_p; -end;' language 'plpgsql' stable; +END; +$$ LANGUAGE plpgsql stable; -select define_function_args('content_item__relate','item_id,object_id,relation_tag;generic,order_n,relation_type;cr_item_rel'); -create or replace function content_item__relate (integer,integer,varchar,integer,varchar) -returns integer as ' -declare - relate__item_id alias for $1; - relate__object_id alias for $2; - relate__relation_tag alias for $3; -- default ''generic'' - relate__order_n alias for $4; -- default null - relate__relation_type alias for $5; -- default ''cr_item_rel'' + +-- old define_function_args('content_item__relate','item_id,object_id,relation_tag;generic,order_n,relation_type;cr_item_rel') +-- new +select define_function_args('content_item__relate','item_id,object_id,relation_tag;generic,order_n;null,relation_type;cr_item_rel'); + + + +-- +-- procedure content_item__relate/5 +-- +CREATE OR REPLACE FUNCTION content_item__relate( + relate__item_id integer, + relate__object_id integer, + relate__relation_tag varchar, -- default 'generic' + relate__order_n integer, -- default null + relate__relation_type varchar -- default 'cr_item_rel' + +) RETURNS integer AS $$ +DECLARE v_content_type cr_items.content_type%TYPE; v_object_type acs_objects.object_type%TYPE; v_is_valid integer; v_rel_id integer; v_package_id integer; v_exists integer; v_order_n cr_item_rels.order_n%TYPE; -begin +BEGIN -- check the relationship is valid v_content_type := content_item__get_content_type (relate__item_id); @@ -2687,17 +3087,17 @@ from cr_type_relations where - content_item__is_subclass( v_object_type, target_type ) = ''t'' + content_item__is_subclass( v_object_type, target_type ) = 't' and - content_item__is_subclass( v_content_type, content_type ) = ''t''; + content_item__is_subclass( v_content_type, content_type ) = 't'; if v_is_valid = 0 then - raise EXCEPTION ''-20000: There is no registered relation type matching this item relation.''; + raise EXCEPTION '-20000: There is no registered relation type matching this item relation.'; end if; if relate__item_id != relate__object_id then -- check that these two items are not related already - --dbms_output.put_line( ''checking if the items are already related...''); + --dbms_output.put_line( 'checking if the items are already related...'); select rel_id, 1 into v_rel_id, v_exists @@ -2726,16 +3126,16 @@ -- if relationship does not exist, create it if v_exists <> 1 then - --dbms_output.put_line( ''creating new relationship...''); + --dbms_output.put_line( 'creating new relationship...'); v_rel_id := acs_object__new( null, relate__relation_type, now(), null, null, relate__item_id, - ''t'', - relate__relation_tag || '': '' || relate__item_id || '' - '' || relate__object_id, + 't', + relate__relation_tag || ': ' || relate__item_id || ' - ' || relate__object_id, v_package_id ); @@ -2748,70 +3148,88 @@ -- if relationship already exists, update it else - --dbms_output.put_line( ''updating existing relationship...''); + --dbms_output.put_line( 'updating existing relationship...'); update cr_item_rels set relation_tag = relate__relation_tag, order_n = v_order_n where rel_id = v_rel_id; update acs_objects set - title = relate__relation_tag || '': '' || relate__item_id || '' - '' || relate__object_id + title = relate__relation_tag || ': ' || relate__item_id || ' - ' || relate__object_id where object_id = v_rel_id; end if; end if; return v_rel_id; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select define_function_args('content_item__unrelate','rel_id'); select define_function_args('content_item__unrelate','rel_id'); -create or replace function content_item__unrelate (integer) -returns integer as ' -declare - unrelate__rel_id alias for $1; -begin + +-- +-- procedure content_item__unrelate/1 +-- +CREATE OR REPLACE FUNCTION content_item__unrelate( + unrelate__rel_id integer +) RETURNS integer AS $$ +DECLARE +BEGIN + -- delete the relation object PERFORM acs_rel__delete(unrelate__rel_id); -- delete the row from the cr_item_rels table delete from cr_item_rels where rel_id = unrelate__rel_id; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select define_function_args('content_item__is_index_page','item_id,folder_id'); select define_function_args('content_item__is_index_page','item_id,folder_id'); -create or replace function content_item__is_index_page (integer,integer) -returns boolean as ' -declare - is_index_page__item_id alias for $1; - is_index_page__folder_id alias for $2; -begin + + +-- +-- procedure content_item__is_index_page/2 +-- +CREATE OR REPLACE FUNCTION content_item__is_index_page( + is_index_page__item_id integer, + is_index_page__folder_id integer +) RETURNS boolean AS $$ +DECLARE +BEGIN if content_folder__get_index_page(is_index_page__folder_id) = is_index_page__item_id then - return ''t''; + return 't'; else - return ''f''; + return 'f'; end if; -end;' language 'plpgsql' stable; +END; +$$ LANGUAGE plpgsql stable; select define_function_args('content_item__get_parent_folder','item_id'); -create or replace function content_item__get_parent_folder (integer) -returns integer as ' -declare - get_parent_folder__item_id alias for $1; + + +-- +-- procedure content_item__get_parent_folder/1 +-- +CREATE OR REPLACE FUNCTION content_item__get_parent_folder( + get_parent_folder__item_id integer +) RETURNS integer AS $$ +DECLARE v_folder_id cr_folders.folder_id%TYPE; - v_parent_folder_p boolean default ''f''; -begin + v_parent_folder_p boolean default 'f'; +BEGIN v_folder_id := get_parent_folder__item_id; while NOT v_parent_folder_p and v_folder_id is not null LOOP @@ -2829,29 +3247,31 @@ return v_folder_id; -end;' language 'plpgsql' stable strict; +END; +$$ LANGUAGE plpgsql stable strict; -- Trigger to maintain context_id in acs_objects -create function cr_items_update_tr () returns opaque as ' -begin +CREATE OR REPLACE FUNCTION cr_items_update_tr () RETURNS trigger AS $$ +BEGIN if new.parent_id <> old.parent_id then update acs_objects set context_id = new.parent_id where object_id = new.item_id; end if; return new; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; create trigger cr_items_update_tr after update on cr_items for each row execute procedure cr_items_update_tr (); -- Trigger to maintain publication audit trail -create function cr_items_publish_update_tr () returns opaque as ' -begin +CREATE OR REPLACE FUNCTION cr_items_publish_update_tr () RETURNS trigger AS $$ +BEGIN if new.live_revision <> old.live_revision or new.publish_status <> old.publish_status then @@ -2868,7 +3288,8 @@ return new; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; create trigger cr_items_publish_update_tr before update on cr_items for each row execute procedure cr_items_publish_update_tr (); Index: openacs-4/packages/acs-content-repository/sql/postgresql/content-keyword.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/sql/postgresql/content-keyword.sql,v diff -u -r1.22 -r1.23 --- openacs-4/packages/acs-content-repository/sql/postgresql/content-keyword.sql 20 Mar 2005 13:41:51 -0000 1.22 +++ openacs-4/packages/acs-content-repository/sql/postgresql/content-keyword.sql 7 Jul 2011 10:46:02 -0000 1.23 @@ -9,47 +9,64 @@ -- http://www.fsf.org/copyleft/gpl.html select define_function_args ('content_keyword__get_heading','keyword_id'); -create or replace function content_keyword__get_heading (integer) -returns text as ' -declare - get_heading__keyword_id alias for $1; + + +-- +-- procedure content_keyword__get_heading/1 +-- +CREATE OR REPLACE FUNCTION content_keyword__get_heading( + get_heading__keyword_id integer +) RETURNS text AS $$ +DECLARE v_heading text; -begin +BEGIN select heading into v_heading from cr_keywords where keyword_id = get_heading__keyword_id; return v_heading; -end;' language 'plpgsql' stable strict; +END; +$$ LANGUAGE plpgsql stable strict; -- function get_description select define_function_args ('content_keyword__get_description','keyword_id'); -create or replace function content_keyword__get_description (integer) -returns text as ' -declare - get_description__keyword_id alias for $1; + + +-- +-- procedure content_keyword__get_description/1 +-- +CREATE OR REPLACE FUNCTION content_keyword__get_description( + get_description__keyword_id integer +) RETURNS text AS $$ +DECLARE v_description text; -begin +BEGIN select description into v_description from cr_keywords where keyword_id = get_description__keyword_id; return v_description; -end;' language 'plpgsql' stable strict; +END; +$$ LANGUAGE plpgsql stable strict; -- procedure set_heading select define_function_args ('content_keyword__set_heading','keyword_id,heading'); -create or replace function content_keyword__set_heading (integer,varchar) -returns integer as ' -declare - set_heading__keyword_id alias for $1; - set_heading__heading alias for $2; -begin + +-- +-- procedure content_keyword__set_heading/2 +-- +CREATE OR REPLACE FUNCTION content_keyword__set_heading( + set_heading__keyword_id integer, + set_heading__heading varchar +) RETURNS integer AS $$ +DECLARE +BEGIN + update cr_keywords set heading = set_heading__heading where @@ -60,64 +77,87 @@ where object_id = set_heading__keyword_id; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure set_description select define_function_args ('content_keyword__set_description','keyword_id,description'); -create or replace function content_keyword__set_description (integer,varchar) -returns integer as ' -declare - set_description__keyword_id alias for $1; - set_description__description alias for $2; -begin + +-- +-- procedure content_keyword__set_description/2 +-- +CREATE OR REPLACE FUNCTION content_keyword__set_description( + set_description__keyword_id integer, + set_description__description varchar +) RETURNS integer AS $$ +DECLARE +BEGIN + update cr_keywords set description = set_description__description where keyword_id = set_description__keyword_id; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function is_leaf select define_function_args ('content_keyword__is_leaf','keyword_id'); -create or replace function content_keyword__is_leaf (integer) -returns boolean as ' -declare - is_leaf__keyword_id alias for $1; -begin + +-- +-- procedure content_keyword__is_leaf/1 +-- +CREATE OR REPLACE FUNCTION content_keyword__is_leaf( + is_leaf__keyword_id integer +) RETURNS boolean AS $$ +DECLARE +BEGIN + return count(*) = 0 from cr_keywords k where k.parent_id = is_leaf__keyword_id; -end;' language 'plpgsql' stable; +END; +$$ LANGUAGE plpgsql stable; -- function new -select define_function_args('content_keyword__new','heading,description,parent_id,keyword_id,creation_date;now,creation_user,creation_ip,object_type;content_keyword'); -create or replace function content_keyword__new (varchar,varchar,integer,integer,timestamptz,integer,varchar,varchar,integer) -returns integer as ' -declare - new__heading alias for $1; - new__description alias for $2; -- default null - new__parent_id alias for $3; -- default null - new__keyword_id alias for $4; -- default null - new__creation_date alias for $5; -- default now() - new__creation_user alias for $6; -- default null - new__creation_ip alias for $7; -- default null - new__object_type alias for $8; -- default ''content_keyword'' - new__package_id alias for $9; -- default null +-- old define_function_args('content_keyword__new','heading,description,parent_id,keyword_id,creation_date;now,creation_user,creation_ip,object_type;content_keyword') +-- new +select define_function_args('content_keyword__new','heading,description;null,parent_id;null,keyword_id;null,creation_date;now,creation_user;null,creation_ip;null,object_type;content_keyword'); + + + + +-- +-- procedure content_keyword__new/9 +-- +CREATE OR REPLACE FUNCTION content_keyword__new( + new__heading varchar, + new__description varchar, -- default null + new__parent_id integer, -- default null + new__keyword_id integer, -- default null + new__creation_date timestamptz, -- default now() -- default 'now' + new__creation_user integer, -- default null + new__creation_ip varchar, -- default null + new__object_type varchar, -- default 'content_keyword' + new__package_id integer -- default null + +) RETURNS integer AS $$ +DECLARE v_id integer; v_package_id acs_objects.package_id%TYPE; -begin +BEGIN if new__package_id is null then v_package_id := acs_object__package_id(new__parent_id); @@ -131,7 +171,7 @@ new__creation_user, new__creation_ip, new__parent_id, - ''t'', + 't', new__heading, v_package_id ); @@ -143,20 +183,27 @@ return v_id; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create or replace function content_keyword__new (varchar,varchar,integer,integer,timestamptz,integer,varchar,varchar) -returns integer as ' -declare - new__heading alias for $1; - new__description alias for $2; -- default null - new__parent_id alias for $3; -- default null - new__keyword_id alias for $4; -- default null - new__creation_date alias for $5; -- default now() - new__creation_user alias for $6; -- default null - new__creation_ip alias for $7; -- default null - new__object_type alias for $8; -- default ''content_keyword'' -begin + + +-- +-- procedure content_keyword__new/8 +-- +CREATE OR REPLACE FUNCTION content_keyword__new( + new__heading varchar, + new__description varchar, -- default null + new__parent_id integer, -- default null + new__keyword_id integer, -- default null + new__creation_date timestamptz, -- default now() -- default 'now' + new__creation_user integer, -- default null + new__creation_ip varchar, -- default null + new__object_type varchar -- default 'content_keyword' + +) RETURNS integer AS $$ +DECLARE +BEGIN return content_keyword__new(new__heading, new__description, new__parent_id, @@ -168,16 +215,22 @@ null ); -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure delete select define_function_args ('content_keyword__del','keyword_id'); -create or replace function content_keyword__del (integer) -returns integer as ' -declare - delete__keyword_id alias for $1; + + +-- +-- procedure content_keyword__del/1 +-- +CREATE OR REPLACE FUNCTION content_keyword__del( + delete__keyword_id integer +) RETURNS integer AS $$ +DECLARE v_rec record; -begin +BEGIN for v_rec in select item_id from cr_item_keyword_map where keyword_id = delete__keyword_id LOOP @@ -187,31 +240,47 @@ PERFORM acs_object__delete(delete__keyword_id); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create or replace function content_keyword__delete (integer) -returns integer as ' -declare - delete__keyword_id alias for $1; + + +-- added +select define_function_args('content_keyword__delete','keyword_id'); + +-- +-- procedure content_keyword__delete/1 +-- +CREATE OR REPLACE FUNCTION content_keyword__delete( + delete__keyword_id integer +) RETURNS integer AS $$ +DECLARE v_rec record; -begin +BEGIN perform content_keyword__del(delete__keyword_id); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure item_assign select define_function_args ('content_keyword__item_assign','item_id,keyword_id,context_id;null,creation_user;null,creation_ip;null'); -create or replace function content_keyword__item_assign (integer,integer,integer,integer,varchar) -returns integer as ' -declare - item_assign__item_id alias for $1; - item_assign__keyword_id alias for $2; - item_assign__context_id alias for $3; -- default null - item_assign__creation_user alias for $4; -- default null - item_assign__creation_ip alias for $5; -- default null + + +-- +-- procedure content_keyword__item_assign/5 +-- +CREATE OR REPLACE FUNCTION content_keyword__item_assign( + item_assign__item_id integer, + item_assign__keyword_id integer, + item_assign__context_id integer, -- default null + item_assign__creation_user integer, -- default null + item_assign__creation_ip varchar -- default null + +) RETURNS integer AS $$ +DECLARE exists_p boolean; -begin +BEGIN -- Do nothing if the keyword is assigned already select count(*) > 0 into exists_p from dual @@ -229,52 +298,65 @@ end if; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure item_unassign select define_function_args ('content_keyword__item_unassign','item_id,keyword_id'); -create or replace function content_keyword__item_unassign (integer,integer) -returns integer as ' -declare - item_unassign__item_id alias for $1; - item_unassign__keyword_id alias for $2; -begin + +-- +-- procedure content_keyword__item_unassign/2 +-- +CREATE OR REPLACE FUNCTION content_keyword__item_unassign( + item_unassign__item_id integer, + item_unassign__keyword_id integer +) RETURNS integer AS $$ +DECLARE +BEGIN + delete from cr_item_keyword_map where item_id = item_unassign__item_id and keyword_id = item_unassign__keyword_id; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function is_assigned select define_function_args ('content_keyword__is_assigned','item_id,keyword_id,recurse;none'); -create or replace function content_keyword__is_assigned (integer,integer,varchar) -returns boolean as ' -declare - is_assigned__item_id alias for $1; - is_assigned__keyword_id alias for $2; - is_assigned__recurse alias for $3; -- default ''none'' + + +-- +-- procedure content_keyword__is_assigned/3 +-- +CREATE OR REPLACE FUNCTION content_keyword__is_assigned( + is_assigned__item_id integer, + is_assigned__keyword_id integer, + is_assigned__recurse varchar -- default 'none' + +) RETURNS boolean AS $$ +DECLARE v_ret boolean; v_is_assigned__recurse varchar; -begin +BEGIN if is_assigned__recurse is null then - v_is_assigned__recurse := ''none''; + v_is_assigned__recurse := 'none'; else v_is_assigned__recurse := is_assigned__recurse; end if; -- Look for an exact match - if v_is_assigned__recurse = ''none'' then + if v_is_assigned__recurse = 'none' then return count(*) > 0 from cr_item_keyword_map where item_id = is_assigned__item_id and keyword_id = is_assigned__keyword_id; end if; -- Look from specific to general - if v_is_assigned__recurse = ''up'' then + if v_is_assigned__recurse = 'up' then return count(*) > 0 where exists (select 1 from (select keyword_id from cr_keywords c, cr_keywords c2 @@ -285,7 +367,7 @@ and m.item_id = is_assigned__item_id); end if; - if v_is_assigned__recurse = ''down'' then + if v_is_assigned__recurse = 'down' then return count(*) > 0 where exists (select 1 from (select k2.keyword_id @@ -299,23 +381,29 @@ end if; -- Tried none, up and down - must be an invalid parameter - raise EXCEPTION ''-20000: The recurse parameter to content_keyword.is_assigned should be \\\'none\\\', \\\'up\\\' or \\\'down\\\'''; + raise EXCEPTION '-20000: The recurse parameter to content_keyword.is_assigned should be ''none'', ''up'' or ''down'''; return null; -end;' language 'plpgsql' stable; +END; +$$ LANGUAGE plpgsql stable; -- function get_path select define_function_args ('content_keyword__get_path','keyword_id'); -create or replace function content_keyword__get_path (integer) -returns text as ' -declare - get_path__keyword_id alias for $1; - v_path text default ''''; - v_is_found boolean default ''f''; + + +-- +-- procedure content_keyword__get_path/1 +-- +CREATE OR REPLACE FUNCTION content_keyword__get_path( + get_path__keyword_id integer +) RETURNS text AS $$ +DECLARE + v_path text default ''; + v_is_found boolean default 'f'; v_heading cr_keywords.heading%TYPE; v_rec record; -begin +BEGIN -- select -- heading -- from ( @@ -335,31 +423,33 @@ order by tree_level desc LOOP v_heading := v_rec.heading; - v_is_found := ''t''; - v_path := v_path || ''/'' || v_heading; + v_is_found := 't'; + v_path := v_path || '/' || v_heading; end LOOP; - if v_is_found = ''f'' then + if v_is_found = 'f' then return null; else return v_path; end if; -end;' language 'plpgsql' stable strict; +END; +$$ LANGUAGE plpgsql stable strict; -- Ensure that the context_id in acs_objects is always set to the -- parent_id in cr_keywords -create function cr_keywords_update_tr () returns opaque as ' -begin +CREATE OR REPLACE FUNCTION cr_keywords_update_tr () RETURNS trigger AS $$ +BEGIN if old.parent_id <> new.parent_id then update acs_objects set context_id = new.parent_id where object_id = new.keyword_id; end if; return new; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; create trigger cr_keywords_update_tr after update on cr_keywords for each row execute procedure cr_keywords_update_tr (); Index: openacs-4/packages/acs-content-repository/sql/postgresql/content-perms.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/sql/postgresql/Attic/content-perms.sql,v diff -u -r1.9 -r1.10 --- openacs-4/packages/acs-content-repository/sql/postgresql/content-perms.sql 23 Feb 2003 06:45:07 -0000 1.9 +++ openacs-4/packages/acs-content-repository/sql/postgresql/content-perms.sql 7 Jul 2011 10:46:02 -0000 1.10 @@ -5,47 +5,54 @@ -- -------------------------------------------------------------- -create function inline_0 () -returns integer as ' -declare + + +-- +-- procedure inline_0/0 +-- +CREATE OR REPLACE FUNCTION inline_0( + +) RETURNS integer AS $$ +DECLARE found_p boolean; -begin +BEGIN select count(*) > 0 into found_p from dual where exists (select 1 from acs_privileges - where privilege = ''cm_root''); + where privilege = 'cm_root'); if NOT found_p then -- Dummy root privilege - PERFORM acs_privilege__create_privilege(''cm_root'', ''Root'', ''Root''); + PERFORM acs_privilege__create_privilege('cm_root', 'Root', 'Root'); -- He can do everything - PERFORM acs_privilege__create_privilege(''cm_admin'', ''Administrator'', ''Administrators''); - PERFORM acs_privilege__create_privilege(''cm_write'', ''Write'', ''Write''); - PERFORM acs_privilege__create_privilege(''cm_new'', ''Create New Item'', ''Create New Item''); - PERFORM acs_privilege__create_privilege(''cm_examine'', ''Admin-level Read'', ''Admin-level Read''); - PERFORM acs_privilege__create_privilege(''cm_read'', ''User-level Read'', ''User-level Read''); - PERFORM acs_privilege__create_privilege(''cm_item_workflow'', ''Modify Workflow'', ''Modify Workflow''); - PERFORM acs_privilege__create_privilege(''cm_perm_admin'', ''Modify Any Permissions'', ''Modify Any Permissions''); - PERFORM acs_privilege__create_privilege(''cm_perm'', ''Donate Permissions'', ''Donate Permissions''); + PERFORM acs_privilege__create_privilege('cm_admin', 'Administrator', 'Administrators'); + PERFORM acs_privilege__create_privilege('cm_write', 'Write', 'Write'); + PERFORM acs_privilege__create_privilege('cm_new', 'Create New Item', 'Create New Item'); + PERFORM acs_privilege__create_privilege('cm_examine', 'Admin-level Read', 'Admin-level Read'); + PERFORM acs_privilege__create_privilege('cm_read', 'User-level Read', 'User-level Read'); + PERFORM acs_privilege__create_privilege('cm_item_workflow', 'Modify Workflow', 'Modify Workflow'); + PERFORM acs_privilege__create_privilege('cm_perm_admin', 'Modify Any Permissions', 'Modify Any Permissions'); + PERFORM acs_privilege__create_privilege('cm_perm', 'Donate Permissions', 'Donate Permissions'); - PERFORM acs_privilege__add_child(''cm_root'', ''cm_admin''); -- Do anything to an object - PERFORM acs_privilege__add_child(''cm_admin'', ''cm_write''); -- Do anything to an object - PERFORM acs_privilege__add_child(''cm_write'', ''cm_new''); -- Create subitems - PERFORM acs_privilege__add_child(''cm_new'', ''cm_examine''); -- View in admin mode - PERFORM acs_privilege__add_child(''cm_examine'', ''cm_read''); -- View in user mode - PERFORM acs_privilege__add_child(''cm_write'', ''cm_item_workflow''); -- Change item workflow + PERFORM acs_privilege__add_child('cm_root', 'cm_admin'); -- Do anything to an object + PERFORM acs_privilege__add_child('cm_admin', 'cm_write'); -- Do anything to an object + PERFORM acs_privilege__add_child('cm_write', 'cm_new'); -- Create subitems + PERFORM acs_privilege__add_child('cm_new', 'cm_examine'); -- View in admin mode + PERFORM acs_privilege__add_child('cm_examine', 'cm_read'); -- View in user mode + PERFORM acs_privilege__add_child('cm_write', 'cm_item_workflow'); -- Change item workflow - PERFORM acs_privilege__add_child(''cm_admin'', ''cm_perm_admin''); -- Modify any permissions - PERFORM acs_privilege__add_child(''cm_perm_admin'', ''cm_perm''); -- Modify any permissions on an item + PERFORM acs_privilege__add_child('cm_admin', 'cm_perm_admin'); -- Modify any permissions + PERFORM acs_privilege__add_child('cm_perm_admin', 'cm_perm'); -- Modify any permissions on an item -- Proper inheritance - PERFORM acs_privilege__add_child(''admin'', ''cm_root''); + PERFORM acs_privilege__add_child('admin', 'cm_root'); end if; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select inline_0 (); @@ -54,14 +61,23 @@ -- create or replace package body content_permission -- procedure inherit_permissions -create function content_permission__inherit_permissions (integer,integer,integer) -returns integer as ' -declare - inherit_permissions__parent_object_id alias for $1; - inherit_permissions__child_object_id alias for $2; - inherit_permissions__child_creator_id alias for $3; -- default null + + +-- added +select define_function_args('content_permission__inherit_permissions','parent_object_id,child_object_id,child_creator_id;null'); + +-- +-- procedure content_permission__inherit_permissions/3 +-- +CREATE OR REPLACE FUNCTION content_permission__inherit_permissions( + inherit_permissions__parent_object_id integer, + inherit_permissions__child_object_id integer, + inherit_permissions__child_creator_id integer -- default null + +) RETURNS integer AS $$ +DECLARE v_dummy integer; -begin +BEGIN -- Determine if the child is a direct descendant of the -- parent @@ -70,7 +86,7 @@ and context_id = inherit_permissions__parent_object_id; if NOT FOUND then - raise EXCEPTION ''-20000: Child object is not actually a child of the parent object in inherit_permissions''; + raise EXCEPTION '-20000: Child object is not actually a child of the parent object in inherit_permissions'; end if; -- Copy everything one level down @@ -89,73 +105,91 @@ if content_permission__permission_p ( inherit_permissions__child_object_id, inherit_permissions__child_creator_id, - ''cm_perm'' - ) != ''t'' then + 'cm_perm' + ) != 't' then -- Turn off inheritance and grant permission - update acs_objects set security_inherit_p = ''f'' + update acs_objects set security_inherit_p = 'f' where object_id = inherit_permissions__child_object_id; PERFORM acs_permission__grant_permission ( inherit_permissions__child_object_id, inherit_permissions__child_creator_id, - ''cm_perm'' + 'cm_perm' ); end if; if content_permission__permission_p ( inherit_permissions__child_object_id, inherit_permissions__child_creator_id, - ''cm_write'' - ) != ''t'' then + 'cm_write' + ) != 't' then PERFORM acs_permission__grant_permission ( inherit_permissions__child_object_id, inherit_permissions__child_creator_id, - ''cm_write'' + 'cm_write' ); end if; end if; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function has_grant_authority -create function content_permission__has_grant_authority (integer,integer,varchar) -returns boolean as ' -declare - object_id alias for $1; - holder_id alias for $2; - privilege alias for $3; -begin + + +-- added +select define_function_args('content_permission__has_grant_authority','object_id,holder_id,privilege'); + +-- +-- procedure content_permission__has_grant_authority/3 +-- +CREATE OR REPLACE FUNCTION content_permission__has_grant_authority( + object_id integer, + holder_id integer, + privilege varchar +) RETURNS boolean AS $$ +DECLARE +BEGIN -- Can donate permission only if you already have it and you have cm_perm, -- OR you have cm_perm_admin - if content_permission__permission_p (object_id, holder_id, ''cm_perm_admin'')= ''t'' + if content_permission__permission_p (object_id, holder_id, 'cm_perm_admin')= 't' or ( - content_permission__permission_p (object_id, holder_id, ''cm_perm'') = ''t'' and - content_permission__permission_p (object_id, holder_id, privilege) = ''t'' + content_permission__permission_p (object_id, holder_id, 'cm_perm') = 't' and + content_permission__permission_p (object_id, holder_id, privilege) = 't' ) then - return ''t''; + return 't'; else - return ''f''; + return 'f'; end if; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function has_revoke_authority -create function content_permission__has_revoke_authority (integer,integer,varchar,integer) -returns boolean as ' -declare - has_revoke_authority__object_id alias for $1; - has_revoke_authority__holder_id alias for $2; - has_revoke_authority__privilege alias for $3; - has_revoke_authority__revokee_id alias for $4; -begin + +-- added +select define_function_args('content_permission__has_revoke_authority','object_id,holder_id,privilege,revokee_id'); + +-- +-- procedure content_permission__has_revoke_authority/4 +-- +CREATE OR REPLACE FUNCTION content_permission__has_revoke_authority( + has_revoke_authority__object_id integer, + has_revoke_authority__holder_id integer, + has_revoke_authority__privilege varchar, + has_revoke_authority__revokee_id integer +) RETURNS boolean AS $$ +DECLARE +BEGIN + -- DRB: Note that the privilege selection doesn't use the slick tree_ancestor_keys -- trick. There are two reasons for this. The first is that we might have a set of -- tree_sortkeys returned from the acs_privilege_hierarchy_index when child_privilege - -- is ''cm_perm''. The second is that this table is relatively small anyway and the + -- is 'cm_perm'. The second is that this table is relatively small anyway and the -- old style's probably just as efficient as the first as an index scan is only preferred -- by the Postgres optimizer when it will significantly reduce the number of rows scanned. @@ -178,31 +212,40 @@ t.object_id, has_revoke_authority__revokee_id, h.privilege )); -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure grant_permission_h -create function content_permission__grant_permission_h (integer,integer,varchar) -returns integer as ' -declare - grant_permission_h__object_id alias for $1; - grant_permission_h__grantee_id alias for $2; - grant_permission_h__privilege alias for $3; + + +-- added +select define_function_args('content_permission__grant_permission_h','object_id,grantee_id,privilege'); + +-- +-- procedure content_permission__grant_permission_h/3 +-- +CREATE OR REPLACE FUNCTION content_permission__grant_permission_h( + grant_permission_h__object_id integer, + grant_permission_h__grantee_id integer, + grant_permission_h__privilege varchar +) RETURNS integer AS $$ +DECLARE v_privilege acs_privilege_descendant_map.privilege%TYPE; v_rec record; -begin +BEGIN -- If the permission is already granted, do nothing if content_permission__permission_p ( grant_permission_h__object_id, grant_permission_h__grantee_id, grant_permission_h__privilege - ) = ''t'' then + ) = 't' then return null; end if; -- Grant the parent, make sure there is no inheritance - update acs_objects set security_inherit_p = ''f'' + update acs_objects set security_inherit_p = 'f' where object_id = grant_permission_h__object_id; PERFORM acs_permission__grant_permission(grant_permission_h__object_id, @@ -223,21 +266,31 @@ end LOOP; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure grant_permission -create function content_permission__grant_permission (integer,integer,varchar,integer,boolean,varchar) -returns integer as ' -declare - grant_permission__object_id alias for $1; - grant_permission__holder_id alias for $2; - grant_permission__privilege alias for $3; - grant_permission__recepient_id alias for $4; - grant_permission__is_recursive alias for $5; -- default ''f'' - grant_permission__object_type alias for $6; -- default ''content_item'' + + +-- added +select define_function_args('content_permission__grant_permission','object_id,holder_id,privilege,recepient_id,is_recursive;f,object_type;content_item'); + +-- +-- procedure content_permission__grant_permission/6 +-- +CREATE OR REPLACE FUNCTION content_permission__grant_permission( + grant_permission__object_id integer, + grant_permission__holder_id integer, + grant_permission__privilege varchar, + grant_permission__recepient_id integer, + grant_permission__is_recursive boolean, -- default 'f' + grant_permission__object_type varchar -- default 'content_item' + +) RETURNS integer AS $$ +DECLARE v_object_id acs_objects.object_id%TYPE; -begin +BEGIN -- select -- o.object_id -- from @@ -247,9 +300,9 @@ -- where -- content_permission__has_grant_authority ( -- o.object_id, holder_id, grant_permission__privilege --- ) = ''t'' +-- ) = 't' -- and --- content_item__is_subclass (o.object_type, grant_permission__object_type) = ''t'' +-- content_item__is_subclass (o.object_type, grant_permission__object_type) = 't' for v_rec in select o.object_id @@ -268,22 +321,31 @@ grant_permission__recepient_id, grant_permission__privilege ); - exit when grant_permission__is_recursive = ''f''; + exit when grant_permission__is_recursive = 'f'; end loop; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure revoke_permission_h -create function content_permission__revoke_permission_h (integer,integer,varchar) -returns integer as ' -declare - revoke_permission_h__object_id alias for $1; - revoke_permission_h__revokee_id alias for $2; - revoke_permission_h__privilege alias for $3; + + +-- added +select define_function_args('content_permission__revoke_permission_h','object_id,revokee_id,privilege'); + +-- +-- procedure content_permission__revoke_permission_h/3 +-- +CREATE OR REPLACE FUNCTION content_permission__revoke_permission_h( + revoke_permission_h__object_id integer, + revoke_permission_h__revokee_id integer, + revoke_permission_h__privilege varchar +) RETURNS integer AS $$ +DECLARE v_rec record; -begin +BEGIN -- Grant all child privileges of the parent privilege for v_rec in select child_privilege from acs_privilege_hierarchy @@ -304,21 +366,31 @@ ); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure revoke_permission -create function content_permission__revoke_permission (integer,integer,varchar,integer,boolean,varchar) -returns integer as ' -declare - revoke_permission__object_id alias for $1; - revoke_permission__holder_id alias for $2; - revoke_permission__privilege alias for $3; - revoke_permission__revokee_id alias for $4; - revoke_permission__is_recursive alias for $5; -- default ''f'' - revoke_permission__object_type alias for $6; -- default ''content_item'' + + +-- added +select define_function_args('content_permission__revoke_permission','object_id,holder_id,privilege,revokee_id,is_recursive;f,object_type;content_item'); + +-- +-- procedure content_permission__revoke_permission/6 +-- +CREATE OR REPLACE FUNCTION content_permission__revoke_permission( + revoke_permission__object_id integer, + revoke_permission__holder_id integer, + revoke_permission__privilege varchar, + revoke_permission__revokee_id integer, + revoke_permission__is_recursive boolean, -- default 'f' + revoke_permission__object_type varchar -- default 'content_item' + +) RETURNS integer AS $$ +DECLARE v_rec record; -begin +BEGIN -- select object_id, object_type from acs_objects -- connect by context_id = prior object_id -- start with object_id = revoke_permission__object_id @@ -329,47 +401,58 @@ where o1.tree_sortkey between o2.tree_sortkey and tree_right(o2.tree_sortkey) and o2.object_id = revoke_permission__object_id) o where - content_permission__has_revoke_authority (o.object_id, revoke_permission__holder_id, revoke_permission__privilege, revoke_permission__revokee_id) = ''t'' + content_permission__has_revoke_authority (o.object_id, revoke_permission__holder_id, revoke_permission__privilege, revoke_permission__revokee_id) = 't' and - content_item__is_subclass(o.object_type, revoke_permission__object_type) = ''t'' + content_item__is_subclass(o.object_type, revoke_permission__object_type) = 't' LOOP PERFORM content_permission__revoke_permission_h ( v_rec.object_id, revoke_permission__revokee_id, revoke_permission__privilege ); - exit when revoke_permission__is_recursive = ''f''; + exit when revoke_permission__is_recursive = 'f'; end loop; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function permission_p -create function content_permission__permission_p (integer,integer,varchar) -returns boolean as ' -declare - object_id alias for $1; - holder_id alias for $2; - privilege alias for $3; -begin + +-- added +select define_function_args('content_permission__permission_p','object_id,holder_id,privilege'); + +-- +-- procedure content_permission__permission_p/3 +-- +CREATE OR REPLACE FUNCTION content_permission__permission_p( + object_id integer, + holder_id integer, + privilege varchar +) RETURNS boolean AS $$ +DECLARE +BEGIN + return acs_permission__permission_p (object_id, holder_id, privilege); -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- Determine if the CMS admin exists -create function cm_admin_exists () returns boolean as ' -begin +CREATE OR REPLACE FUNCTION cm_admin_exists () RETURNS boolean AS $$ +BEGIN return count(*) > 0 from dual where exists ( select 1 from acs_permissions - where privilege in (''cm_admin'', ''cm_root'') + where privilege in ('cm_admin', 'cm_root') ); -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- show errors Index: openacs-4/packages/acs-content-repository/sql/postgresql/content-revision.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/sql/postgresql/content-revision.sql,v diff -u -r1.46 -r1.47 --- openacs-4/packages/acs-content-repository/sql/postgresql/content-revision.sql 10 Feb 2009 18:31:54 -0000 1.46 +++ openacs-4/packages/acs-content-repository/sql/postgresql/content-revision.sql 7 Jul 2011 10:46:02 -0000 1.47 @@ -19,26 +19,34 @@ -- than the standard package_instantiate_object. So we don't bother calling define_function_args -- here. -create or replace function content_revision__new (varchar,varchar,timestamptz,varchar,varchar,integer,integer,integer,timestamptz,integer,varchar,integer) -returns integer as ' -declare - new__title alias for $1; - new__description alias for $2; -- default null - new__publish_date alias for $3; -- default now() - new__mime_type alias for $4; -- default ''text/plain'' - new__nls_language alias for $5; -- default null + + +-- added + +-- +-- procedure content_revision__new/12 +-- +CREATE OR REPLACE FUNCTION content_revision__new( + new__title varchar, + new__description varchar, -- default null + new__publish_date timestamptz, -- default now() + new__mime_type varchar, -- default 'text/plain' + new__nls_language varchar, -- default null + new__data integer, + new__item_id integer, + new__revision_id integer, -- default null + new__creation_date timestamptz, -- default now() + new__creation_user integer, -- default null + new__creation_ip varchar, -- default null + new__package_id integer -- default null + +) RETURNS integer AS $$ +DECLARE -- lob id - new__data alias for $6; - new__item_id alias for $7; - new__revision_id alias for $8; -- default null - new__creation_date alias for $9; -- default now() - new__creation_user alias for $10; -- default null - new__creation_ip alias for $11; -- default null - new__package_id alias for $12; -- default null v_revision_id integer; v_package_id acs_objects.package_id%TYPE; v_content_type acs_object_types.object_type%TYPE; -begin +BEGIN v_content_type := content_item__get_content_type(new__item_id); @@ -55,7 +63,7 @@ new__creation_user, new__creation_ip, new__item_id, - ''t'', + 't', new__title, v_package_id ); @@ -80,24 +88,31 @@ return v_revision_id; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create or replace function content_revision__new (varchar,varchar,timestamptz,varchar,varchar,integer,integer,integer,timestamptz,integer,varchar) -returns integer as ' -declare - new__title alias for $1; - new__description alias for $2; -- default null - new__publish_date alias for $3; -- default now() - new__mime_type alias for $4; -- default ''text/plain'' - new__nls_language alias for $5; -- default null + + +-- +-- procedure content_revision__new/11 +-- +CREATE OR REPLACE FUNCTION content_revision__new( + new__title varchar, + new__description varchar, -- default null + new__publish_date timestamptz, -- default now() + new__mime_type varchar, -- default 'text/plain' + new__nls_language varchar, -- default null + new__data integer, + new__item_id integer, + new__revision_id integer, -- default null + new__creation_date timestamptz, -- default now() + new__creation_user integer, -- default null + new__creation_ip varchar -- default null + +) RETURNS integer AS $$ +DECLARE -- lob id - new__data alias for $6; - new__item_id alias for $7; - new__revision_id alias for $8; -- default null - new__creation_date alias for $9; -- default now() - new__creation_user alias for $10; -- default null - new__creation_ip alias for $11; -- default null -begin +BEGIN return content_revision__new(new__title, new__description, new__publish_date, @@ -111,18 +126,26 @@ new__creation_ip, null ); -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create or replace function content_revision__new(varchar,varchar,timestamptz,varchar,text,integer,integer) returns integer as ' -declare - new__title alias for $1; - new__description alias for $2; -- default null - new__publish_date alias for $3; -- default now() - new__mime_type alias for $4; -- default ''text/plain'' - new__text alias for $5; -- default '' '' - new__item_id alias for $6; - new__package_id alias for $7; -- default null -begin + + +-- +-- procedure content_revision__new/7 +-- +CREATE OR REPLACE FUNCTION content_revision__new( + new__title varchar, + new__description varchar, -- default null + new__publish_date timestamptz, -- default now() + new__mime_type varchar, -- default 'text/plain' + new__text text, -- default ' ' + new__item_id integer, + new__package_id integer -- default null + +) RETURNS integer AS $$ +DECLARE +BEGIN return content_revision__new(new__title, new__description, new__publish_date, @@ -138,17 +161,25 @@ new__package_id ); -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create or replace function content_revision__new(varchar,varchar,timestamptz,varchar,text,integer) returns integer as ' -declare - new__title alias for $1; - new__description alias for $2; -- default null - new__publish_date alias for $3; -- default now() - new__mime_type alias for $4; -- default ''text/plain'' - new__text alias for $5; -- default '' '' - new__item_id alias for $6; -begin + + +-- +-- procedure content_revision__new/6 +-- +CREATE OR REPLACE FUNCTION content_revision__new( + new__title varchar, + new__description varchar, -- default null + new__publish_date timestamptz, -- default now() + new__mime_type varchar, -- default 'text/plain' + new__text text, -- default ' ' + new__item_id integer + +) RETURNS integer AS $$ +DECLARE +BEGIN return content_revision__new(new__title, new__description, new__publish_date, @@ -164,23 +195,30 @@ null ); -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create or replace function content_revision__new (varchar,varchar,timestamptz,varchar,varchar,text,integer,integer,timestamptz,integer,varchar) -returns integer as ' -declare - new__title alias for $1; - new__description alias for $2; -- default null - new__publish_date alias for $3; -- default now() - new__mime_type alias for $4; -- default ''text/plain'' - new__nls_language alias for $5; -- default null - new__text alias for $6; -- default '' '' - new__item_id alias for $7; - new__revision_id alias for $8; -- default null - new__creation_date alias for $9; -- default now() - new__creation_user alias for $10; -- default null - new__creation_ip alias for $11; -- default null -begin + + +-- +-- procedure content_revision__new/11 +-- +CREATE OR REPLACE FUNCTION content_revision__new( + new__title varchar, + new__description varchar, -- default null + new__publish_date timestamptz, -- default now() + new__mime_type varchar, -- default 'text/plain' + new__nls_language varchar, -- default null + new__text text, -- default ' ' + new__item_id integer, + new__revision_id integer, -- default null + new__creation_date timestamptz, -- default now() + new__creation_user integer, -- default null + new__creation_ip varchar -- default null + +) RETURNS integer AS $$ +DECLARE +BEGIN return content_revision__new(new__title, new__description, new__publish_date, @@ -195,24 +233,33 @@ null, null ); -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create or replace function content_revision__new (varchar,varchar,timestamptz,varchar,varchar,text,integer,integer,timestamptz,integer,varchar,integer) -returns integer as ' -declare - new__title alias for $1; - new__description alias for $2; -- default null - new__publish_date alias for $3; -- default now() - new__mime_type alias for $4; -- default ''text/plain'' - new__nls_language alias for $5; -- default null - new__text alias for $6; -- default '' '' - new__item_id alias for $7; - new__revision_id alias for $8; -- default null - new__creation_date alias for $9; -- default now() - new__creation_user alias for $10; -- default null - new__creation_ip alias for $11; -- default null - new__content_length alias for $12; -- default null -begin + + +-- added + +-- +-- procedure content_revision__new/12 +-- +CREATE OR REPLACE FUNCTION content_revision__new( + new__title varchar, + new__description varchar, -- default null + new__publish_date timestamptz, -- default now() + new__mime_type varchar, -- default 'text/plain' + new__nls_language varchar, -- default null + new__text text, -- default ' ' + new__item_id integer, + new__revision_id integer, -- default null + new__creation_date timestamptz, -- default now() + new__creation_user integer, -- default null + new__creation_ip varchar, -- default null + new__content_length integer -- default null + +) RETURNS integer AS $$ +DECLARE +BEGIN return content_revision__new(new__title, new__description, new__publish_date, @@ -227,31 +274,41 @@ new__content_length, null ); -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function new -create or replace function content_revision__new (varchar,varchar,timestamptz,varchar,varchar,text,integer,integer,timestamptz,integer,varchar,integer,integer) -returns integer as ' -declare - new__title alias for $1; - new__description alias for $2; -- default null - new__publish_date alias for $3; -- default now() - new__mime_type alias for $4; -- default ''text/plain'' - new__nls_language alias for $5; -- default null - new__text alias for $6; -- default '' '' - new__item_id alias for $7; - new__revision_id alias for $8; -- default null - new__creation_date alias for $9; -- default now() - new__creation_user alias for $10; -- default null - new__creation_ip alias for $11; -- default null - new__content_length alias for $12; -- default null - new__package_id alias for $13; -- default null + + +-- added +select define_function_args('content_revision__new','title,description;null,publish_date;now(),mime_type;text/plain,nls_language;null,text; ,item_id,revision_id;null,creation_date;now(),creation_user;null,creation_ip;null,content_length;null,package_id;null'); + +-- +-- procedure content_revision__new/13 +-- +CREATE OR REPLACE FUNCTION content_revision__new( + new__title varchar, + new__description varchar, -- default null + new__publish_date timestamptz, -- default now() + new__mime_type varchar, -- default 'text/plain' + new__nls_language varchar, -- default null + new__text text, -- default ' ' + new__item_id integer, + new__revision_id integer, -- default null + new__creation_date timestamptz, -- default now() + new__creation_user integer, -- default null + new__creation_ip varchar, -- default null + new__content_length integer, -- default null + new__package_id integer -- default null + +) RETURNS integer AS $$ +DECLARE v_revision_id integer; v_package_id acs_objects.package_id%TYPE; v_content_type acs_object_types.object_type%TYPE; v_storage_type cr_items.storage_type%TYPE; v_length cr_revisions.content_length%TYPE; -begin +BEGIN v_content_type := content_item__get_content_type(new__item_id); @@ -268,7 +325,7 @@ new__creation_user, new__creation_ip, new__item_id, - ''t'', + 't', new__title, v_package_id ); @@ -277,7 +334,7 @@ from cr_items where item_id = new__item_id; - if v_storage_type = ''text'' then + if v_storage_type = 'text' then v_length := length(new__text); else v_length := coalesce(new__content_length,0); @@ -297,25 +354,31 @@ return v_revision_id; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure copy_attributes select define_function_args('content_revision__copy_attributes','content_type,revision_id,copy_id'); -create or replace function content_revision__copy_attributes (varchar,integer,integer) -returns integer as ' -declare - copy_attributes__content_type alias for $1; - copy_attributes__revision_id alias for $2; - copy_attributes__copy_id alias for $3; + + +-- +-- procedure content_revision__copy_attributes/3 +-- +CREATE OR REPLACE FUNCTION content_revision__copy_attributes( + copy_attributes__content_type varchar, + copy_attributes__revision_id integer, + copy_attributes__copy_id integer +) RETURNS integer AS $$ +DECLARE v_table_name acs_object_types.table_name%TYPE; v_id_column acs_object_types.id_column%TYPE; - cols varchar default ''''; + cols varchar default ''; attr_rec record; -begin +BEGIN if copy_attributes__content_type is null or copy_attributes__revision_id is null or copy_attributes__copy_id is null then - raise exception ''content_revision__copy_attributes called with null % % %'',copy_attributes__content_type,copy_attributes__revision_id, copy_attributes__copy_id; + raise exception 'content_revision__copy_attributes called with null % % %',copy_attributes__content_type,copy_attributes__revision_id, copy_attributes__copy_id; end if; select table_name, id_column into v_table_name, v_id_column @@ -328,33 +391,44 @@ where object_type = copy_attributes__content_type LOOP - cols := cols || '', '' || attr_rec.attribute_name; + cols := cols || ', ' || attr_rec.attribute_name; end loop; - execute ''insert into '' || v_table_name || ''('' || v_id_column || cols || '')'' || '' select '' || copy_attributes__copy_id || - '' as '' || v_id_column || cols || '' from '' || - v_table_name || '' where '' || v_id_column || '' = '' || + execute 'insert into ' || v_table_name || '(' || v_id_column || cols || ')' || ' select ' || copy_attributes__copy_id || + ' as ' || v_id_column || cols || ' from ' || + v_table_name || ' where ' || v_id_column || ' = ' || copy_attributes__revision_id; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function copy -select define_function_args('content_revision__copy','revision_id,copy_id,target_item_id,creation_user,creation_ip'); -create or replace function content_revision__copy (integer,integer,integer,integer,varchar) -returns integer as ' -declare - copy__revision_id alias for $1; - copy__copy_id alias for $2; -- default null - copy__target_item_id alias for $3; -- default null - copy__creation_user alias for $4; -- default null - copy__creation_ip alias for $5; -- default null + +-- old define_function_args('content_revision__copy','revision_id,copy_id,target_item_id,creation_user,creation_ip') +-- new +select define_function_args('content_revision__copy','revision_id,copy_id;null,target_item_id;null,creation_user;null,creation_ip;null'); + + + +-- +-- procedure content_revision__copy/5 +-- +CREATE OR REPLACE FUNCTION content_revision__copy( + copy__revision_id integer, + copy__copy_id integer, -- default null + copy__target_item_id integer, -- default null + copy__creation_user integer, -- default null + copy__creation_ip varchar -- default null + +) RETURNS integer AS $$ +DECLARE v_copy_id cr_revisions.revision_id%TYPE; v_target_item_id cr_items.item_id%TYPE; type_rec record; -begin +BEGIN -- use the specified item_id or the item_id of the original revision -- if none is specified if copy__target_item_id is null then @@ -367,7 +441,7 @@ -- use the copy_id or generate a new copy_id if none is specified -- the copy_id is a revision_id if copy__copy_id is null then - select nextval(''t_acs_object_id_seq'') into v_copy_id from dual; + select nextval('t_acs_object_id_seq') into v_copy_id from dual; else v_copy_id := copy__copy_id; end if; @@ -425,8 +499,8 @@ -- iterate over the ancestor types and copy attributes for type_rec in select ot2.object_type, tree_level(ot2.tree_sortkey) as level from acs_object_types ot1, acs_object_types ot2, acs_objects o - where ot2.object_type <> ''acs_object'' - and ot2.object_type <> ''content_revision'' + where ot2.object_type <> 'acs_object' + and ot2.object_type <> 'content_revision' and o.object_id = copy__revision_id and ot1.object_type = o.object_type and ot1.tree_sortkey between ot2.tree_sortkey and tree_right(ot2.tree_sortkey) @@ -438,20 +512,26 @@ return v_copy_id; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure delete select define_function_args('content_revision__del','revision_id'); -create or replace function content_revision__del (integer) -returns integer as ' -declare - delete__revision_id alias for $1; + + +-- +-- procedure content_revision__del/1 +-- +CREATE OR REPLACE FUNCTION content_revision__del( + delete__revision_id integer +) RETURNS integer AS $$ +DECLARE v_item_id cr_items.item_id%TYPE; v_latest_revision cr_revisions.revision_id%TYPE; v_live_revision cr_revisions.revision_id%TYPE; v_rec record; -begin +BEGIN -- Get item id and latest/live revisions select item_id into v_item_id from cr_revisions @@ -503,29 +583,41 @@ PERFORM acs_object__delete(delete__revision_id); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select define_function_args('content_revision__delete','revision_id'); -create or replace function content_revision__delete (integer) -returns integer as ' -declare - delete__revision_id alias for $1; -begin + + +-- +-- procedure content_revision__delete/1 +-- +CREATE OR REPLACE FUNCTION content_revision__delete( + delete__revision_id integer +) RETURNS integer AS $$ +DECLARE +BEGIN PERFORM content_revision__del(delete__revision_id); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function get_number select define_function_args('content_revision__get_number','revision_id'); -create or replace function content_revision__get_number (integer) -returns integer as ' -declare - get_number__revision_id alias for $1; + + +-- +-- procedure content_revision__get_number/1 +-- +CREATE OR REPLACE FUNCTION content_revision__get_number( + get_number__revision_id integer +) RETURNS integer AS $$ +DECLARE v_revision cr_revisions.revision_id%TYPE; v_row_count integer default 0; rev_cur record; -begin +BEGIN for rev_cur in select revision_id from @@ -547,32 +639,44 @@ return null; -end;' language 'plpgsql' stable strict; +END; +$$ LANGUAGE plpgsql stable strict; select define_function_args('content_revision__revision_name','revision_id'); -create or replace function content_revision__revision_name(integer) -returns text as ' -declare - p_revision_id alias for $1; -begin - return ''Revision '' || content_revision__get_number(revision_id) || - '' of '' || (select count(*) from cr_revisions where item_id = r.item_id) || '' for item: '' + + +-- +-- procedure content_revision__revision_name/1 +-- +CREATE OR REPLACE FUNCTION content_revision__revision_name( + p_revision_id integer +) RETURNS text AS $$ +DECLARE +BEGIN + return 'Revision ' || content_revision__get_number(revision_id) || + ' of ' || (select count(*) from cr_revisions where item_id = r.item_id) || ' for item: ' || content_item__get_title(item_id) from cr_revisions r where r.revision_id = p_revision_id; -end;' language 'plpgsql' stable strict; +END; +$$ LANGUAGE plpgsql stable strict; -- procedure to_html select define_function_args('content_revision__to_html','revision_id'); -create or replace function content_revision__to_html (integer) -returns integer as ' -declare - to_html__revision_id alias for $1; + + +-- +-- procedure content_revision__to_html/1 +-- +CREATE OR REPLACE FUNCTION content_revision__to_html( + to_html__revision_id integer +) RETURNS integer AS $$ +DECLARE tmp_clob text; blob_loc integer; -begin +BEGIN -- FIXME - -- ctx_doc.filter(''cr_doc_filter_index'', revision_id, tmp_clob); + -- ctx_doc.filter('cr_doc_filter_index', revision_id, tmp_clob); select content into blob_loc @@ -587,50 +691,71 @@ PERFORM dbms_lob__freetemporary(tmp_clob); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function is_live select define_function_args('content_revision__is_live','revision_id'); -create or replace function content_revision__is_live (integer) -returns boolean as ' -declare - is_live__revision_id alias for $1; -begin + +-- +-- procedure content_revision__is_live/1 +-- +CREATE OR REPLACE FUNCTION content_revision__is_live( + is_live__revision_id integer +) RETURNS boolean AS $$ +DECLARE +BEGIN + return count(*) > 0 from cr_items where live_revision = is_live__revision_id; -end;' language 'plpgsql' strict; +END; +$$ LANGUAGE plpgsql strict; -- function is_latest select define_function_args('content_revision__is_latest','revision_id'); -create or replace function content_revision__is_latest (integer) -returns boolean as ' -declare - is_latest__revision_id alias for $1; -begin + +-- +-- procedure content_revision__is_latest/1 +-- +CREATE OR REPLACE FUNCTION content_revision__is_latest( + is_latest__revision_id integer +) RETURNS boolean AS $$ +DECLARE +BEGIN + return count(*) > 0 from cr_items where latest_revision = is_latest__revision_id; -end;' language 'plpgsql' stable; +END; +$$ LANGUAGE plpgsql stable; -- procedure to_temporary_clob -create or replace function content_revision__to_temporary_clob (integer) -returns integer as ' -declare - to_temporary_clob__revision_id alias for $1; + + +-- added +select define_function_args('content_revision__to_temporary_clob','revision_id'); + +-- +-- procedure content_revision__to_temporary_clob/1 +-- +CREATE OR REPLACE FUNCTION content_revision__to_temporary_clob( + to_temporary_clob__revision_id integer +) RETURNS integer AS $$ +DECLARE -- b blob; -- c text; -begin +BEGIN -- FIXME: I cannot find an instance in the 4.2 beta code where this -- is used so I am not worrying about porting it for now. -- DCW - 2001-03-28. - raise EXCEPTION ''not implemented content_revision.to_temporary_clob''; + raise EXCEPTION 'not implemented content_revision.to_temporary_clob'; /* insert into cr_content_text ( revision_id, content @@ -644,26 +769,37 @@ PERFORM blob_to_clob(b, c); */ return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure content_copy -select define_function_args('content_revision__content_copy','revision_id,revision_id_dest'); -create or replace function content_revision__content_copy (integer,integer) -returns integer as ' -declare - content_copy__revision_id alias for $1; - content_copy__revision_id_dest alias for $2; -- default null + +-- old define_function_args('content_revision__content_copy','revision_id,revision_id_dest') +-- new +select define_function_args('content_revision__content_copy','revision_id,revision_id_dest;null'); + + + +-- +-- procedure content_revision__content_copy/2 +-- +CREATE OR REPLACE FUNCTION content_revision__content_copy( + content_copy__revision_id integer, + content_copy__revision_id_dest integer -- default null + +) RETURNS integer AS $$ +DECLARE v_item_id cr_items.item_id%TYPE; v_content_length cr_revisions.content_length%TYPE; v_revision_id_dest cr_revisions.revision_id%TYPE; v_content cr_revisions.content%TYPE; v_lob cr_revisions.lob%TYPE; v_new_lob cr_revisions.lob%TYPE; v_storage_type varchar; -begin +BEGIN if content_copy__revision_id is null then - raise exception ''content_revision__content_copy attempt to copy a null revision_id''; + raise exception 'content_revision__content_copy attempt to copy a null revision_id'; end if; select @@ -703,7 +839,7 @@ where r.item_id = i.item_id and r.revision_id = content_copy__revision_id; - if v_storage_type = ''lob'' then + if v_storage_type = 'lob' then v_new_lob := empty_lob(); PERFORM lob_copy(v_lob, v_new_lob); @@ -725,7 +861,7 @@ -- with the new relative file path: -- update cr_revisions - -- set content = ''[cr_create_content_file $item_id $revision_id [cr_fs_path]$old_rel_path]'' + -- set content = '[cr_create_content_file $item_id $revision_id [cr_fs_path]$old_rel_path]' -- where revision_id = :revision_id -- old_rel_path is the content attribute value of the content revision @@ -740,45 +876,53 @@ end if; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure content__get_content select define_function_args('content_revision__get_content','revision_id'); -create or replace function content_revision__get_content (integer) -returns text as ' -declare - get_content__revision_id alias for $1; + + +-- +-- procedure content_revision__get_content/1 +-- +CREATE OR REPLACE FUNCTION content_revision__get_content( + get_content__revision_id integer +) RETURNS text AS $$ +DECLARE v_storage_type varchar; v_lob_id integer; v_data text; -begin +BEGIN select i.storage_type, r.lob into v_storage_type, v_lob_id from cr_items i, cr_revisions r where i.item_id = r.item_id and r.revision_id = get_content__revision_id; - if v_storage_type = ''lob'' then + if v_storage_type = 'lob' then return v_lob_id::text; else return content from cr_revisions where revision_id = get_content__revision_id; end if; -end;' language 'plpgsql' stable strict; +END; +$$ LANGUAGE plpgsql stable strict; -- show errors -- Trigger to maintain latest_revision in cr_items -create function cr_revision_latest_tr () returns opaque as ' -begin +CREATE OR REPLACE FUNCTION cr_revision_latest_tr () RETURNS trigger AS $$ +BEGIN update cr_items set latest_revision = new.revision_id where item_id = new.item_id; return new; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; create trigger cr_revision_latest_tr after insert on cr_revisions for each row execute procedure cr_revision_latest_tr (); Index: openacs-4/packages/acs-content-repository/sql/postgresql/content-schedule.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/sql/postgresql/content-schedule.sql,v diff -u -r1.9 -r1.10 --- openacs-4/packages/acs-content-repository/sql/postgresql/content-schedule.sql 4 Jun 2006 00:45:23 -0000 1.9 +++ openacs-4/packages/acs-content-repository/sql/postgresql/content-schedule.sql 7 Jul 2011 10:46:02 -0000 1.10 @@ -12,13 +12,14 @@ -- prompt *** Preparing for scheduled updates to live content... -create function cr_scheduled_release_tr () returns opaque as ' -begin +CREATE OR REPLACE FUNCTION cr_scheduled_release_tr () RETURNS trigger AS $$ +BEGIN - raise EXCEPTION ''-20000: Inserts are not allowed into cr_scheduled_release_job.''; + raise EXCEPTION '-20000: Inserts are not allowed into cr_scheduled_release_job.'; return new; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; create trigger cr_scheduled_release_tr before insert on cr_scheduled_release_job @@ -29,16 +30,23 @@ -- Update the publishing status for items that are due to be released -- or expired. -create function cr_scheduled_release_exec () returns integer as ' -declare + + +-- +-- procedure cr_scheduled_release_exec/0 +-- +CREATE OR REPLACE FUNCTION cr_scheduled_release_exec( + +) RETURNS integer AS $$ +DECLARE exec__last_exec timestamptz; exec__this_exec timestamptz default current_timestamp; exec__items_released integer default 0; exec__items_expired integer default 0; exec__err_num integer; -- sqlcode exec__err_msg varchar; -- substr(sqlerrm, 1, 500); item_rec record; -begin +BEGIN select last_exec into exec__last_exec from cr_scheduled_release_job; @@ -53,7 +61,7 @@ LOOP -- update publish status update cr_items - set publish_status = ''live'' + set publish_status = 'live' where item_id = item_rec.item_id; exec__items_released := exec__items_released + 1; @@ -70,7 +78,7 @@ LOOP -- update publish status update cr_items - set publish_status = ''expired'' + set publish_status = 'expired' where item_id = item_rec.item_id; @@ -96,10 +104,11 @@ -- Table was growing without bound (OpenACS DanW) delete from cr_scheduled_release_log - where exec_date < now() - ''4 week''::interval; + where exec_date < now() - '4 week'::interval; -- Reset the last time of execution to start of processing update cr_scheduled_release_job set last_exec = exec__this_exec; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; Index: openacs-4/packages/acs-content-repository/sql/postgresql/content-search.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/sql/postgresql/content-search.sql,v diff -u -r1.8 -r1.9 --- openacs-4/packages/acs-content-repository/sql/postgresql/content-search.sql 6 Sep 2006 14:46:03 -0000 1.8 +++ openacs-4/packages/acs-content-repository/sql/postgresql/content-search.sql 7 Jul 2011 10:46:02 -0000 1.9 @@ -83,27 +83,33 @@ -create function content_search__itrg () -returns opaque as ' -begin +CREATE OR REPLACE FUNCTION content_search__itrg () RETURNS trigger AS $$ +BEGIN if (select live_revision from cr_items where item_id=new.item_id) = new.revision_id and new.publish_date >= current_timestamp then - perform search_observer__enqueue(new.revision_id,''INSERT''); + perform search_observer__enqueue(new.revision_id,'INSERT'); end if; return new; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create function content_search__dtrg () -returns opaque as ' -begin - perform search_observer__enqueue(old.revision_id,''DELETE''); +CREATE OR REPLACE FUNCTION content_search__dtrg () RETURNS trigger AS $$ +BEGIN + perform search_observer__enqueue(old.revision_id,'DELETE'); return old; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create or replace function content_search__utrg () -returns opaque as ' -declare + + +-- +-- procedure content_search__utrg/0 +-- +CREATE OR REPLACE FUNCTION content_search__utrg( + +) RETURNS trigger AS $$ +DECLARE v_live_revision integer; -begin +BEGIN select into v_live_revision live_revision from cr_items where item_id=old.item_id; if old.revision_id=v_live_revision @@ -113,31 +119,32 @@ event ) values ( old.revision_id, - ''UPDATE'' + 'UPDATE' ); end if; return new; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- we need new triggers on cr_items to index when a live revision -- changes -DaveB 2002-09-26 -create function content_item_search__utrg () -returns opaque as ' -begin +CREATE OR REPLACE FUNCTION content_item_search__utrg () RETURNS trigger AS $$ +BEGIN if new.live_revision is not null and coalesce(old.live_revision,0) <> new.live_revision and (select publish_date from cr_revisions where revision_id=new.live_revision) <= current_timestamp then - perform search_observer__enqueue(new.live_revision,''INSERT''); + perform search_observer__enqueue(new.live_revision,'INSERT'); end if; if old.live_revision is not null and old.live_revision <> coalesce(new.live_revision,0) then - perform search_observer__enqueue(old.live_revision,''DELETE''); + perform search_observer__enqueue(old.live_revision,'DELETE'); end if; - if new.publish_status = ''expired'' then - perform search_observer__enqueue(old.live_revision,''DELETE''); + if new.publish_status = 'expired' then + perform search_observer__enqueue(old.live_revision,'DELETE'); end if; return new; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; create trigger content_search__itrg after insert on cr_revisions for each row execute procedure content_search__itrg (); Index: openacs-4/packages/acs-content-repository/sql/postgresql/content-symlink.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/sql/postgresql/content-symlink.sql,v diff -u -r1.20 -r1.21 --- openacs-4/packages/acs-content-repository/sql/postgresql/content-symlink.sql 4 Jun 2006 00:45:23 -0000 1.20 +++ openacs-4/packages/acs-content-repository/sql/postgresql/content-symlink.sql 7 Jul 2011 10:46:02 -0000 1.21 @@ -12,57 +12,67 @@ -- create or replace package body content_symlink -- function new -select define_function_args('content_symlink__new','name,label,target_id,parent_id,symlink_id,creation_date;now,creation_user,creation_ip,package_id'); -create or replace function content_symlink__new (varchar,varchar,integer,integer,integer,timestamptz,integer,varchar,integer) -returns integer as ' -declare - new__name alias for $1; -- default null - new__label alias for $2; -- default null - new__target_id alias for $3; - new__parent_id alias for $4; - new__symlink_id alias for $5; -- default null - new__creation_date alias for $6; -- default now() - new__creation_user alias for $7; -- default null - new__creation_ip alias for $8; -- default null - new__package_id alias for $9; -- default null +-- old define_function_args('content_symlink__new','name,label,target_id,parent_id,symlink_id,creation_date;now,creation_user,creation_ip,package_id') +-- new +select define_function_args('content_symlink__new','name;null,label;null,target_id,parent_id,symlink_id;null,creation_date;now,creation_user;null,creation_ip;null,package_id;null'); + + + + +-- +-- procedure content_symlink__new/9 +-- +CREATE OR REPLACE FUNCTION content_symlink__new( + new__name varchar, -- default null + new__label varchar, -- default null + new__target_id integer, + new__parent_id integer, + new__symlink_id integer, -- default null + new__creation_date timestamptz, -- default now() -- default 'now' + new__creation_user integer, -- default null + new__creation_ip varchar, -- default null + new__package_id integer -- default null + +) RETURNS integer AS $$ +DECLARE v_symlink_id cr_symlinks.symlink_id%TYPE; v_package_id acs_objects.package_id%TYPE; v_name cr_items.name%TYPE; v_label cr_symlinks.label%TYPE; v_ctype varchar; -begin +BEGIN -- SOME CHECKS -- -- 1) check that the target is now a symlink - if content_symlink__is_symlink(new__target_id) = ''t'' then - raise EXCEPTION ''-20000: Cannot create a symlink to a symlink %'', new__target_id; + if content_symlink__is_symlink(new__target_id) = 't' then + raise EXCEPTION '-20000: Cannot create a symlink to a symlink %', new__target_id; end if; -- 2) check that the parent is a folder - if content_folder__is_folder(new__parent_id) = ''f'' then - raise EXCEPTION ''-20000: The parent is not a folder''; + if content_folder__is_folder(new__parent_id) = 'f' then + raise EXCEPTION '-20000: The parent is not a folder'; end if; -- 3) check that parent folder supports symlinks - if content_folder__is_registered(new__parent_id,''content_symlink'',''f'') = ''f'' then - raise EXCEPTION ''-20000: This folder does not allow symlinks to be created''; + if content_folder__is_registered(new__parent_id,'content_symlink','f') = 'f' then + raise EXCEPTION '-20000: This folder does not allow symlinks to be created'; end if; -- 4) check that the content folder supports the target items content type - if content_folder__is_registered(new__parent_id, content_item__get_content_type(new__target_id), ''f'') = ''f'' then + if content_folder__is_registered(new__parent_id, content_item__get_content_type(new__target_id), 'f') = 'f' then v_ctype := content_item__get_content_type(new__target_id); - raise EXCEPTION ''-20000: This folder does not allow symlinks to items of type % to be created'', v_ctype; + raise EXCEPTION '-20000: This folder does not allow symlinks to items of type % to be created', v_ctype; end if; -- PASSED ALL CHECKS -- -- Select default name if the name is null - if new__name is null or new__name = '''' then + if new__name is null or new__name = '' then select - ''symlink_to_'' || name into v_name + 'symlink_to_' || name into v_name from cr_items where @@ -77,7 +87,7 @@ -- Select default label if the label is null if new__label is null then - v_label := ''Symlink to '' || v_name; + v_label := 'Symlink to ' || v_name; else v_label := new__label; end if; @@ -97,14 +107,14 @@ new__creation_user, null, new__creation_ip, - ''content_item'', - ''content_symlink'', + 'content_item', + 'content_symlink', null, null, - ''text/plain'', + 'text/plain', null, null, - ''text'', + 'text', v_package_id ); @@ -119,21 +129,31 @@ return v_symlink_id; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create or replace function content_symlink__new (varchar,varchar,integer,integer,integer,timestamptz,integer,varchar) -returns integer as ' -declare - new__name alias for $1; -- default null - new__label alias for $2; -- default null - new__target_id alias for $3; - new__parent_id alias for $4; - new__symlink_id alias for $5; -- default null - new__creation_date alias for $6; -- default now() - new__creation_user alias for $7; -- default null - new__creation_ip alias for $8; -- default null -begin + + +-- +-- procedure content_symlink__new/8 +-- +CREATE OR REPLACE FUNCTION content_symlink__new( + new__name varchar, -- default null + new__label varchar, -- default null + new__target_id integer, + new__parent_id integer, + new__symlink_id integer, -- default null + new__creation_date timestamptz, -- default now() + new__creation_user integer, -- default null + new__creation_ip varchar -- default null + +) RETURNS integer AS $$ +-- +-- content_symlink__new/8 maybe obsolete, when we define proper defaults for /9 +-- +DECLARE +BEGIN return content_extlink__new(new__name, new__label, new__target_id, @@ -145,47 +165,65 @@ null ); -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure delete select define_function_args('content_symlink__delete','symlink_id'); -create or replace function content_symlink__delete (integer) -returns integer as ' -declare - delete__symlink_id alias for $1; -begin + +-- +-- procedure content_symlink__delete/1 +-- +CREATE OR REPLACE FUNCTION content_symlink__delete( + delete__symlink_id integer +) RETURNS integer AS $$ +DECLARE +BEGIN + PERFORM content_symlink__del(delete__symlink_id); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select define_function_args('content_symlink__del','symlink_id'); -create or replace function content_symlink__del (integer) -returns integer as ' -declare - del__symlink_id alias for $1; -begin + +-- +-- procedure content_symlink__del/1 +-- +CREATE OR REPLACE FUNCTION content_symlink__del( + del__symlink_id integer +) RETURNS integer AS $$ +DECLARE +BEGIN + delete from cr_symlinks where symlink_id = del__symlink_id; PERFORM content_item__delete(del__symlink_id); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function is_symlink select define_function_args('content_symlink__is_symlink','item_id'); -create or replace function content_symlink__is_symlink (integer) -returns boolean as ' -declare - is_symlink__item_id alias for $1; + + +-- +-- procedure content_symlink__is_symlink/1 +-- +CREATE OR REPLACE FUNCTION content_symlink__is_symlink( + is_symlink__item_id integer +) RETURNS boolean AS $$ +DECLARE v_symlink_p boolean; -begin +BEGIN select count(*) = 1 into v_symlink_p @@ -196,32 +234,39 @@ return v_symlink_p; -end;' language 'plpgsql' stable; +END; +$$ LANGUAGE plpgsql stable; -- procedure copy -select define_function_args('content_symlink__copy','symlink_id,target_folder_id,creation_user,creation_ip,name'); -create or replace function content_symlink__copy ( - integer, - integer, - integer, - varchar, - varchar) returns integer as ' -declare - copy__symlink_id alias for $1; - copy__target_folder_id alias for $2; - copy__creation_user alias for $3; - copy__creation_ip alias for $4; -- default null - copy__name alias for $5; -- default null + +-- old define_function_args('content_symlink__copy','symlink_id,target_folder_id,creation_user,creation_ip,name') +-- new +select define_function_args('content_symlink__copy','symlink_id,target_folder_id,creation_user,creation_ip;null,name;null'); + + + +-- +-- procedure content_symlink__copy/5 +-- +CREATE OR REPLACE FUNCTION content_symlink__copy( + copy__symlink_id integer, + copy__target_folder_id integer, + copy__creation_user integer, + copy__creation_ip varchar, -- default null + copy__name varchar -- default null + +) RETURNS integer AS $$ +DECLARE v_current_folder_id cr_folders.folder_id%TYPE; v_name cr_items.name%TYPE; v_target_id cr_items.item_id%TYPE; v_label cr_symlinks.label%TYPE; v_symlink_id cr_symlinks.symlink_id%TYPE; -begin +BEGIN -- XXX: bug if target is not a folder this will silently fail. - if content_folder__is_folder(copy__target_folder_id) = ''t'' then + if content_folder__is_folder(copy__target_folder_id) = 't' then select parent_id into @@ -231,7 +276,7 @@ where item_id = copy__symlink_id; - -- can''t copy to the same folder unless name is different + -- can't copy to the same folder unless name is different select i.name, content_symlink__resolve(i.item_id), s.label @@ -248,9 +293,9 @@ -- is different if copy__target_folder_id != v_current_folder_id or ( v_name <> copy_name and copy_name is not null ) then if content_folder__is_registered(copy__target_folder_id, - ''content_symlink'',''f'') = ''t'' then + 'content_symlink','f') = 't' then if content_folder__is_registered(copy__target_folder_id, - content_item__get_content_type(content_symlink__resolve(copy__symlink_id)),''f'') = ''t'' then + content_item__get_content_type(content_symlink__resolve(copy__symlink_id)),'f') = 't' then v_symlink_id := content_symlink__new( coalesce (copy__name,v_name), @@ -271,25 +316,31 @@ end if; return v_symlink_id; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create or replace function content_symlink__copy ( - integer, - integer, - integer, - varchar) -returns integer as ' -declare - copy__symlink_id alias for $1; - copy__target_folder_id alias for $2; - copy__creation_user alias for $3; - copy__creation_ip alias for $4; -- default null + + +-- +-- procedure content_symlink__copy/4 +-- +CREATE OR REPLACE FUNCTION content_symlink__copy( + copy__symlink_id integer, + copy__target_folder_id integer, + copy__creation_user integer, + copy__creation_ip varchar -- default null + +) RETURNS integer AS $$ +-- +-- content_symlink__copy/4 maybe obsolete, when we define proper defaults for /5 +-- +DECLARE v_current_folder_id cr_folders.folder_id%TYPE; v_name cr_items.name%TYPE; v_target_id cr_items.item_id%TYPE; v_label cr_symlinks.label%TYPE; v_symlink_id cr_symlinks.symlink_id%TYPE; -begin +BEGIN v_symlink_id := content_symlink__copy ( copy__symlink_id, copy__target_folder_id, @@ -298,16 +349,22 @@ NULL ); return v_symlink_id; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function resolve select define_function_args('content_symlink__resolve','item_id'); -create or replace function content_symlink__resolve (integer) -returns integer as ' -declare - resolve__item_id alias for $1; + + +-- +-- procedure content_symlink__resolve/1 +-- +CREATE OR REPLACE FUNCTION content_symlink__resolve( + resolve__item_id integer +) RETURNS integer AS $$ +DECLARE v_target_id cr_items.item_id%TYPE; -begin +BEGIN select target_id into v_target_id @@ -322,17 +379,23 @@ return v_target_id; end if; -end;' language 'plpgsql' stable strict; +END; +$$ LANGUAGE plpgsql stable strict; -- function resolve_content_type select define_function_args('content_symlink__resolve_content_type','item_id'); -create or replace function content_symlink__resolve_content_type (integer) -returns varchar as ' -declare - resolve_content_type__item_id alias for $1; + + +-- +-- procedure content_symlink__resolve_content_type/1 +-- +CREATE OR REPLACE FUNCTION content_symlink__resolve_content_type( + resolve_content_type__item_id integer +) RETURNS varchar AS $$ +DECLARE v_content_type cr_items.content_type%TYPE; -begin +BEGIN select content_item__get_content_type(target_id) into v_content_type @@ -343,7 +406,8 @@ return v_content_type; -end;' language 'plpgsql' stable strict; +END; +$$ LANGUAGE plpgsql stable strict; Index: openacs-4/packages/acs-content-repository/sql/postgresql/content-template.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/sql/postgresql/content-template.sql,v diff -u -r1.24 -r1.25 --- openacs-4/packages/acs-content-repository/sql/postgresql/content-template.sql 4 Oct 2010 21:59:20 -0000 1.24 +++ openacs-4/packages/acs-content-repository/sql/postgresql/content-template.sql 7 Jul 2011 10:46:02 -0000 1.25 @@ -13,20 +13,37 @@ create view content_template_globals as select -200 as c_root_folder_id; -create or replace function content_template__get_root_folder() returns integer as ' -declare + + +-- +-- procedure content_template__get_root_folder/0 +-- +CREATE OR REPLACE FUNCTION content_template__get_root_folder( + +) RETURNS integer AS $$ +DECLARE v_folder_id integer; -begin +BEGIN select c_root_folder_id from content_template_globals into v_folder_id; return v_folder_id; -end;' language 'plpgsql' immutable; +END; +$$ LANGUAGE plpgsql immutable; -- create or replace package body content_template -create or replace function content_template__new(varchar) returns integer as ' -declare - new__name alias for $1; -begin + + +-- +-- procedure content_template__new/1 +-- +CREATE OR REPLACE FUNCTION content_template__new( + new__name varchar +) RETURNS integer AS $$ +-- +-- content_template__new/1 maybe obsolete, when we define proper defaults for /8 +-- +DECLARE +BEGIN return content_template__new(new__name, null, null, @@ -35,34 +52,44 @@ null ); -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function new -create or replace function content_template__new (varchar,integer,integer,timestamptz,integer,varchar) -returns integer as ' -declare - new__name alias for $1; - new__parent_id alias for $2; -- default null - new__template_id alias for $3; -- default null - new__creation_date alias for $4; -- default now() - new__creation_user alias for $5; -- default null - new__creation_ip alias for $6; -- default null + + +-- +-- procedure content_template__new/6 +-- +CREATE OR REPLACE FUNCTION content_template__new( + new__name varchar, + new__parent_id integer, -- default null + new__template_id integer, -- default null + new__creation_date timestamptz, -- default now() + new__creation_user integer, -- default null + new__creation_ip varchar -- default null + +) RETURNS integer AS $$ +-- +-- content_template__new/6 maybe obsolete, when we define proper defaults for /8 +-- +DECLARE v_template_id cr_templates.template_id%TYPE; v_parent_id cr_items.parent_id%TYPE; -begin +BEGIN if new__parent_id is null then select c_root_folder_id into v_parent_id from content_template_globals; else v_parent_id := new__parent_id; end if; - -- make sure we''re allowed to create a template in this folder - if content_folder__is_folder(new__parent_id) = ''t'' and - content_folder__is_registered(new__parent_id,''content_template'',''f'') = ''f'' then + -- make sure we're allowed to create a template in this folder + if content_folder__is_folder(new__parent_id) = 't' and + content_folder__is_registered(new__parent_id,'content_template','f') = 'f' then - raise EXCEPTION ''-20000: This folder does not allow templates to be created''; + raise EXCEPTION '-20000: This folder does not allow templates to be created'; else v_template_id := content_item__new ( @@ -74,14 +101,14 @@ new__creation_user, null, new__creation_ip, - ''content_item'', - ''content_template'', + 'content_item', + 'content_template', null, null, - ''text/plain'', + 'text/plain', null, null, - ''text'' + 'text' ); insert into cr_templates ( @@ -94,15 +121,25 @@ end if; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create or replace function content_template__new(varchar,text,bool) returns integer as ' -declare - new__name alias for $1; - new__text alias for $2; - new__is_live alias for $3; -begin + + +-- +-- procedure content_template__new/3 +-- +CREATE OR REPLACE FUNCTION content_template__new( + new__name varchar, + new__text text, + new__is_live bool +) RETURNS integer AS $$ +-- +-- content_template__new/3 maybe obsolete, when we define proper defaults for /8 +-- +DECLARE +BEGIN return content_template__new(new__name, null, null, @@ -113,36 +150,47 @@ new__is_live ); -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -select define_function_args('content_template__new','name,parent_id,template_id,creation_date;now,creation_user,creation_ip,text,is_live;f'); -create or replace function content_template__new (varchar,integer,integer,timestamptz,integer,varchar,text,bool) -returns integer as ' -declare - new__name alias for $1; - new__parent_id alias for $2; -- default null - new__template_id alias for $3; -- default null - new__creation_date alias for $4; -- default now() - new__creation_user alias for $5; -- default null - new__creation_ip alias for $6; -- default null - new__text alias for $7; -- default null - new__is_live alias for $8; -- default ''f'' +-- old define_function_args('content_template__new','name,parent_id,template_id,creation_date;now,creation_user,creation_ip,text,is_live;f') +-- new +select define_function_args('content_template__new','name,parent_id;null,template_id;null,creation_date;now,creation_user;null,creation_ip;null,text;null,is_live;f'); + + + + +-- +-- procedure content_template__new/8 +-- +CREATE OR REPLACE FUNCTION content_template__new( + new__name varchar, + new__parent_id integer, -- default null + new__template_id integer, -- default null + new__creation_date timestamptz, -- default now() -- default 'now' + new__creation_user integer, -- default null + new__creation_ip varchar, -- default null + new__text text, -- default null + new__is_live bool -- default 'f' + +) RETURNS integer AS $$ +DECLARE v_template_id cr_templates.template_id%TYPE; v_parent_id cr_items.parent_id%TYPE; -begin +BEGIN if new__parent_id is null then select c_root_folder_id into v_parent_id from content_template_globals; else v_parent_id := new__parent_id; end if; - -- make sure we''re allowed to create a template in this folder - if content_folder__is_folder(new__parent_id) = ''t'' and - content_folder__is_registered(new__parent_id,''content_template'',''f'') = ''f'' then + -- make sure we're allowed to create a template in this folder + if content_folder__is_folder(new__parent_id) = 't' and + content_folder__is_registered(new__parent_id,'content_template','f') = 'f' then - raise EXCEPTION ''-20000: This folder does not allow templates to be created''; + raise EXCEPTION '-20000: This folder does not allow templates to be created'; else v_template_id := content_item__new ( @@ -155,13 +203,13 @@ null, -- new__context_id new__creation_ip, -- new__creation_ip new__is_live, -- new__is_live - ''text/plain'', -- new__mime_type + 'text/plain', -- new__mime_type new__text, -- new__text - ''text'', -- new__storage_type - ''t'', -- new__security_inherit_p - ''CR_FILES'', -- new__storage_area_key - ''content_item'', -- new__item_subtype - ''content_template'' -- new__content_type + 'text', -- new__storage_type + 't', -- new__security_inherit_p + 'CR_FILES', -- new__storage_area_key + 'content_item', -- new__item_subtype + 'content_template' -- new__content_type ); insert into cr_templates ( @@ -174,17 +222,23 @@ end if; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure delete select define_function_args('content_template__del','template_id'); -create or replace function content_template__del (integer) -returns integer as ' -declare - delete__template_id alias for $1; -begin + +-- +-- procedure content_template__del/1 +-- +CREATE OR REPLACE FUNCTION content_template__del( + delete__template_id integer +) RETURNS integer AS $$ +DECLARE +BEGIN + delete from cr_type_template_map where template_id = delete__template_id; @@ -197,45 +251,69 @@ PERFORM content_item__delete(delete__template_id); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select define_function_args('content_template__delete','template_id'); -create or replace function content_template__delete (integer) -returns integer as ' -declare - delete__template_id alias for $1; -begin + + +-- +-- procedure content_template__delete/1 +-- +CREATE OR REPLACE FUNCTION content_template__delete( + delete__template_id integer +) RETURNS integer AS $$ +DECLARE +BEGIN PERFORM content_template__delete(delete__template_id); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function is_template select define_function_args('content_template__is_template','template_id'); -create or replace function content_template__is_template (integer) -returns boolean as ' -declare - is_template__template_id alias for $1; -begin + + +-- +-- procedure content_template__is_template/1 +-- +CREATE OR REPLACE FUNCTION content_template__is_template( + is_template__template_id integer +) RETURNS boolean AS $$ +DECLARE +BEGIN return count(*) > 0 from cr_templates where template_id = is_template__template_id; -end;' language 'plpgsql' stable; +END; +$$ LANGUAGE plpgsql stable; -- function get_path -select define_function_args('content_template__get_path','template_id,root_folder_id'); -create or replace function content_template__get_path (integer,integer) -returns varchar as ' -declare - template_id alias for $1; - root_folder_id alias for $2; -- default content_template_globals.c_root_folder_id + +-- old define_function_args('content_template__get_path','template_id,root_folder_id') +-- new +select define_function_args('content_template__get_path','template_id,root_folder_id;content_template_globals.c_root_folder_id'); + + + +-- +-- procedure content_template__get_path/2 +-- +CREATE OR REPLACE FUNCTION content_template__get_path( + template_id integer, + root_folder_id integer -- default content_template_globals.c_root_folder_id + +) RETURNS varchar AS $$ +DECLARE -begin +BEGIN return content_item__get_path(template_id, root_folder_id); -end;' language 'plpgsql' stable; +END; +$$ LANGUAGE plpgsql stable; Index: openacs-4/packages/acs-content-repository/sql/postgresql/content-test.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/sql/postgresql/content-test.sql,v diff -u -r1.10 -r1.11 --- openacs-4/packages/acs-content-repository/sql/postgresql/content-test.sql 1 Jun 2004 22:54:18 -0000 1.10 +++ openacs-4/packages/acs-content-repository/sql/postgresql/content-test.sql 7 Jul 2011 10:46:02 -0000 1.11 @@ -16,26 +16,44 @@ name varchar(400) ); -create function content_test__save_val(integer,varchar) returns integer as ' -declare - v_id alias for $1; - v_name alias for $2; -begin + + +-- added +select define_function_args('content_test__save_val','v_id,v_name'); + +-- +-- procedure content_test__save_val/2 +-- +CREATE OR REPLACE FUNCTION content_test__save_val( + v_id integer, + v_name varchar +) RETURNS integer AS $$ +DECLARE +BEGIN insert into tst_ids (id,name) values (v_id, v_name); return null; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create function content_test__get_val(varchar) returns integer as ' -begin +CREATE OR REPLACE FUNCTION content_test__get_val(varchar) RETURNS integer AS $$ +BEGIN return id from tst_ids where name = $1; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create function content_test__dump() returns text as ' -declare + + +-- +-- procedure content_test__dump/0 +-- +CREATE OR REPLACE FUNCTION content_test__dump( + +) RETURNS text AS $$ +DECLARE v_rec record; - v_str text default ''\\n''; -begin - for v_rec in select repeat('' '',(tree_level(tree_sortkey)*2 - 1)) || name as name, + v_str text default E'\n'; +BEGIN + for v_rec in select repeat(' ',(tree_level(tree_sortkey)*2 - 1)) || name as name, item_id, parent_id, tree_level(tree_sortkey) as level, tree_sortkey @@ -48,26 +66,36 @@ rpad(v_rec.parent_id,6) || rpad(v_rec.level,6) || rpad(v_rec.tree_sortkey,30) || - ''\\n''; + E'\n'; end LOOP; return v_str; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create function content_test__put_line(text) returns integer as ' -begin - raise NOTICE ''%'', $1; +CREATE OR REPLACE FUNCTION content_test__put_line(text) RETURNS integer AS $$ +BEGIN + raise NOTICE '%', $1; return null; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create function cast_char(boolean) returns char as ' -begin - return case when $1 then ''t''::char else ''f''::char end; -end;' language 'plpgsql'; +CREATE OR REPLACE FUNCTION cast_char(boolean) RETURNS char AS $$ +BEGIN + return case when $1 then 't'::char else 'f'::char end; +END; +$$ LANGUAGE plpgsql; -create function content_test__create() returns integer as ' -declare + + +-- +-- procedure content_test__create/0 +-- +CREATE OR REPLACE FUNCTION content_test__create( + +) RETURNS integer AS $$ +DECLARE folder_id cr_folders.folder_id%TYPE; folder_b_id cr_folders.folder_id%TYPE; sub_folder_id cr_folders.folder_id%TYPE; @@ -85,299 +113,307 @@ symlink_b_id cr_symlinks.symlink_id%TYPE; found_folder_id cr_folders.folder_id%TYPE; -begin +BEGIN -- create folders and an item - folder_id := content_folder__new(''grandpa'',''Grandpa'',NULL,-100); - folder_b_id := content_folder__new(''grandma'',''Grandma'',NULL,-100); - sub_folder_id := content_folder__new(''pa'',''Pa'',NULL,folder_id); - sub_sub_folder_id := content_folder__new(''me'',''Me'',NULL,sub_folder_id); - item_id := content_item__new(''puppy'',sub_sub_folder_id); + folder_id := content_folder__new('grandpa','Grandpa',NULL,-100); + folder_b_id := content_folder__new('grandma','Grandma',NULL,-100); + sub_folder_id := content_folder__new('pa','Pa',NULL,folder_id); + sub_sub_folder_id := content_folder__new('me','Me',NULL,sub_folder_id); + item_id := content_item__new('puppy',sub_sub_folder_id); simple_item_id := content_item__new( - ''bunny'', + 'bunny', sub_sub_folder_id, - ''Bugs Bunny'', - ''Simple (Revisionless) Item Test'', - ''Simple (Revisionless) Item Test Text'' + 'Bugs Bunny', + 'Simple (Revisionless) Item Test', + 'Simple (Revisionless) Item Test Text' ); live_revision_id := content_revision__new( - ''Live Revision of Puppy'', - ''Live Revision of Puppy Description'', - to_date(''1999-08-12'',''YYYY-MM-DD''), - ''text/html'', - ''Text for Live Revision of Puppy'', + 'Live Revision of Puppy', + 'Live Revision of Puppy Description', + to_date('1999-08-12','YYYY-MM-DD'), + 'text/html', + 'Text for Live Revision of Puppy', item_id ); late_revision_id := content_revision__new( - ''Latest Revision of Puppy'', - ''Latest Revision of Puppy Description'', - to_date(''2001-09-22'',''YYYY-MM-DD''), - ''text/html'', - ''Text for Latest Revision of Puppy'', + 'Latest Revision of Puppy', + 'Latest Revision of Puppy Description', + to_date('2001-09-22','YYYY-MM-DD'), + 'text/html', + 'Text for Latest Revision of Puppy', item_id ); item_template_id := content_template__new( - ''Item Template'' + 'Item Template' ); type_template_id := content_template__new( - ''Type Template'' + 'Type Template' ); def_type_template_id := content_template__new( - ''Dumb Default Type Template'' + 'Dumb Default Type Template' ); dum_template_id := content_template__new( - ''Default Type Template'' + 'Default Type Template' ); - PERFORM content_test__save_val (folder_id,''folder_id''); - PERFORM content_test__save_val (folder_b_id,''folder_b_id''); - PERFORM content_test__save_val (sub_folder_id,''sub_folder_id''); - PERFORM content_test__save_val (sub_sub_folder_id,''sub_sub_folder_id''); - PERFORM content_test__save_val (item_id,''item_id''); - PERFORM content_test__save_val (simple_item_id,''simple_item_id''); - PERFORM content_test__save_val (live_revision_id,''live_revision_id''); - PERFORM content_test__save_val (late_revision_id,''late_revision_id''); - PERFORM content_test__save_val (item_template_id,''item_template_id''); - PERFORM content_test__save_val (type_template_id,''type_template_id''); - PERFORM content_test__save_val (def_type_template_id,''def_type_template_id''); - PERFORM content_test__save_val (dum_template_id,''dum_template_id''); + PERFORM content_test__save_val (folder_id,'folder_id'); + PERFORM content_test__save_val (folder_b_id,'folder_b_id'); + PERFORM content_test__save_val (sub_folder_id,'sub_folder_id'); + PERFORM content_test__save_val (sub_sub_folder_id,'sub_sub_folder_id'); + PERFORM content_test__save_val (item_id,'item_id'); + PERFORM content_test__save_val (simple_item_id,'simple_item_id'); + PERFORM content_test__save_val (live_revision_id,'live_revision_id'); + PERFORM content_test__save_val (late_revision_id,'late_revision_id'); + PERFORM content_test__save_val (item_template_id,'item_template_id'); + PERFORM content_test__save_val (type_template_id,'type_template_id'); + PERFORM content_test__save_val (def_type_template_id,'def_type_template_id'); + PERFORM content_test__save_val (dum_template_id,'dum_template_id'); - PERFORM content_test__put_line(''-------------------------------------''); - PERFORM content_test__put_line(''CREATING CONTENT FOLDERS AND ITEMS...''); - PERFORM content_test__put_line(''...all tests passed''); - PERFORM content_test__put_line(''Folder grandpa is '' || folder_id); - PERFORM content_test__put_line(''Folder grandma is '' || folder_b_id); - PERFORM content_test__put_line(''Sub folder pa is '' || sub_folder_id); - PERFORM content_test__put_line(''Sub sub folder me is '' || sub_sub_folder_id); - PERFORM content_test__put_line(''Added item puppy to sub sub folder me at '' || item_id); - PERFORM content_test__put_line(''Created simple item bunny to sub sub folder me at '' || simple_item_id); - PERFORM content_test__put_line(''Added a revision to puppy at '' || live_revision_id); - PERFORM content_test__put_line(''Added a revision to puppy at '' || late_revision_id); - PERFORM content_test__put_line(''Created Item Template at '' || item_template_id); - PERFORM content_test__put_line(''Created Type Template at '' || type_template_id); - PERFORM content_test__put_line(''Created Def Type Template at '' || def_type_template_id); - PERFORM content_test__put_line(''Created Dum Def Type Template at '' || dum_template_id); + PERFORM content_test__put_line('-------------------------------------'); + PERFORM content_test__put_line('CREATING CONTENT FOLDERS AND ITEMS...'); + PERFORM content_test__put_line('...all tests passed'); + PERFORM content_test__put_line('Folder grandpa is ' || folder_id); + PERFORM content_test__put_line('Folder grandma is ' || folder_b_id); + PERFORM content_test__put_line('Sub folder pa is ' || sub_folder_id); + PERFORM content_test__put_line('Sub sub folder me is ' || sub_sub_folder_id); + PERFORM content_test__put_line('Added item puppy to sub sub folder me at ' || item_id); + PERFORM content_test__put_line('Created simple item bunny to sub sub folder me at ' || simple_item_id); + PERFORM content_test__put_line('Added a revision to puppy at ' || live_revision_id); + PERFORM content_test__put_line('Added a revision to puppy at ' || late_revision_id); + PERFORM content_test__put_line('Created Item Template at ' || item_template_id); + PERFORM content_test__put_line('Created Type Template at ' || type_template_id); + PERFORM content_test__put_line('Created Def Type Template at ' || def_type_template_id); + PERFORM content_test__put_line('Created Dum Def Type Template at ' || dum_template_id); - PERFORM content_test__put_line(''-----------------------------------''); - PERFORM content_test__put_line(''FOLDERS AND EMPTY FOLDERS AND SUBFOLDERS''); - PERFORM content_test__put_line(''...all tests passed''); - PERFORM content_test__put_line(''Is folder '' || folder_id || '' empty? '' + PERFORM content_test__put_line('-----------------------------------'); + PERFORM content_test__put_line('FOLDERS AND EMPTY FOLDERS AND SUBFOLDERS'); + PERFORM content_test__put_line('...all tests passed'); + PERFORM content_test__put_line('Is folder ' || folder_id || ' empty? ' || cast_char(content_folder__is_empty(folder_id)) ); - PERFORM content_test__put_line(''Is folder '' || sub_sub_folder_id || - '' empty? '' || + PERFORM content_test__put_line('Is folder ' || sub_sub_folder_id || + ' empty? ' || cast_char(content_folder__is_empty(sub_sub_folder_id)) ); - PERFORM content_test__put_line(''Is folder '' || sub_folder_id || - '' empty? '' || + PERFORM content_test__put_line('Is folder ' || sub_folder_id || + ' empty? ' || cast_char(content_folder__is_empty(sub_folder_id)) ); - PERFORM content_test__put_line(''Is folder '' || folder_b_id || - '' empty? '' || + PERFORM content_test__put_line('Is folder ' || folder_b_id || + ' empty? ' || cast_char(content_folder__is_empty(folder_b_id)) ); - PERFORM content_test__put_line(''Is folder '' || folder_id || ''? '' || + PERFORM content_test__put_line('Is folder ' || folder_id || '? ' || cast_char(content_folder__is_folder(folder_id)) ); - PERFORM content_test__put_line(''Is folder '' || item_id || ''? '' || + PERFORM content_test__put_line('Is folder ' || item_id || '? ' || cast_char(content_folder__is_folder(item_id)) ); - PERFORM content_test__put_line(''Is '' || folder_id || '' a subfolder of '' - || sub_folder_id || ''? '' || + PERFORM content_test__put_line('Is ' || folder_id || ' a subfolder of ' + || sub_folder_id || '? ' || cast_char(content_folder__is_sub_folder(sub_folder_id, folder_id )) ); - PERFORM content_test__put_line(''Is '' || sub_folder_id || - '' a subfolder of '' || - folder_id || ''? '' || + PERFORM content_test__put_line('Is ' || sub_folder_id || + ' a subfolder of ' || + folder_id || '? ' || cast_char(content_folder__is_sub_folder(folder_id, sub_folder_id )) ); - PERFORM content_test__put_line(''Is '' || sub_sub_folder_id || - '' a subfolder of '' || - folder_id || ''? '' || + PERFORM content_test__put_line('Is ' || sub_sub_folder_id || + ' a subfolder of ' || + folder_id || '? ' || cast_char(content_folder__is_sub_folder(folder_id, sub_sub_folder_id )) ); - PERFORM content_test__put_line(''Is '' || sub_folder_id || - '' a subfolder of '' || - -1 || ''? '' || + PERFORM content_test__put_line('Is ' || sub_folder_id || + ' a subfolder of ' || + -1 || '? ' || cast_char(content_folder__is_sub_folder(-1, sub_folder_id )) ); - PERFORM content_test__put_line(''-------------------------------------''); - PERFORM content_test__put_line(''LIVE AND LATEST REVISIONS...''); - PERFORM content_test__put_line(''...all tests passed''); - PERFORM content_test__put_line(''Get live_revision_id for item puppy '' || + PERFORM content_test__put_line('-------------------------------------'); + PERFORM content_test__put_line('LIVE AND LATEST REVISIONS...'); + PERFORM content_test__put_line('...all tests passed'); + PERFORM content_test__put_line('Get live_revision_id for item puppy ' || item_id || - '' is '' || - coalesce(content_item__get_live_revision(item_id)::varchar,''null'') + ' is ' || + coalesce(content_item__get_live_revision(item_id)::varchar,'null') ); PERFORM content_item__set_live_revision(live_revision_id); - PERFORM content_test__put_line(''Set '' || live_revision_id || - '' as the live revision for item puppy '' + PERFORM content_test__put_line('Set ' || live_revision_id || + ' as the live revision for item puppy ' || item_id); - PERFORM content_test__put_line(''Get live_revision_id for item puppy '' - || item_id || '' is '' || + PERFORM content_test__put_line('Get live_revision_id for item puppy ' + || item_id || ' is ' || content_item__get_live_revision(item_id) ); - PERFORM content_test__put_line(''Get live_revision_id for item kitty '' || - simple_item_id || '' is '' || - coalesce(content_item__get_live_revision(simple_item_id)::varchar,''null'') + PERFORM content_test__put_line('Get live_revision_id for item kitty ' || + simple_item_id || ' is ' || + coalesce(content_item__get_live_revision(simple_item_id)::varchar,'null') ); - PERFORM content_test__put_line(''Get late_revision_id for item puppy '' || - item_id || '' is '' || + PERFORM content_test__put_line('Get late_revision_id for item puppy ' || + item_id || ' is ' || content_item__get_latest_revision(item_id) ); - PERFORM content_test__put_line(''Get late_revision_id for item bunny '' || - simple_item_id || '' is '' || + PERFORM content_test__put_line('Get late_revision_id for item bunny ' || + simple_item_id || ' is ' || content_item__get_latest_revision(simple_item_id) ); /* PERFORM content_item__register_template(item_id, item_template_id, - ''public'' + 'public' ); */ - PERFORM content_type__register_template(''content_revision'', + PERFORM content_type__register_template('content_revision', type_template_id, - ''public'', - ''f'' + 'public', + 'f' ); - PERFORM content_type__register_template(''content_revision'', + PERFORM content_type__register_template('content_revision', def_type_template_id, - ''admin'', - ''f'' + 'admin', + 'f' ); - PERFORM content_type__register_template(''content_revision'', + PERFORM content_type__register_template('content_revision', dum_template_id, - ''admin'', - ''t'' + 'admin', + 't' ); - PERFORM content_type__set_default_template(''content_revision'', + PERFORM content_type__set_default_template('content_revision', def_type_template_id, - ''admin'' + 'admin' ); - PERFORM content_test__put_line(''-------------------------------------''); - PERFORM content_test__put_line(''REGISTERING TEMPLATES TO ITEMS AND TYPES...''); - PERFORM content_test__put_line(''...all tests passed''); - PERFORM content_test__put_line(''Registered Item Template '' || - item_template_id || '' to item puppy '' || - item_id || '' with public context'' + PERFORM content_test__put_line('-------------------------------------'); + PERFORM content_test__put_line('REGISTERING TEMPLATES TO ITEMS AND TYPES...'); + PERFORM content_test__put_line('...all tests passed'); + PERFORM content_test__put_line('Registered Item Template ' || + item_template_id || ' to item puppy ' || + item_id || ' with public context' ); - PERFORM content_test__put_line(''Registered Type Template '' || - type_template_id || '' to content_revision '' - || item_id || '' with public context'' + PERFORM content_test__put_line('Registered Type Template ' || + type_template_id || ' to content_revision ' + || item_id || ' with public context' ); - PERFORM content_test__put_line(''Registered Default Type Template '' || + PERFORM content_test__put_line('Registered Default Type Template ' || def_type_template_id || - '' to content_revision '' || item_id || - '' with admin context'' + ' to content_revision ' || item_id || + ' with admin context' ); - PERFORM content_test__put_line(''Get template id for item puppy '' || - item_id || '' and context public is '' || + PERFORM content_test__put_line('Get template id for item puppy ' || + item_id || ' and context public is ' || coalesce(content_item__get_template(item_id, - ''public'' - )::varchar,''null'') + 'public' + )::varchar,'null') ); - PERFORM content_test__put_line(''Get template id for item puppy '' || - item_id || '' and context admin is '' || + PERFORM content_test__put_line('Get template id for item puppy ' || + item_id || ' and context admin is ' || content_item__get_template(item_id, - ''admin'' + 'admin' ) ); - found_folder_id := content_item__get_id(''grandpa/pa/me'', -100, ''f''); - PERFORM content_test__save_val (found_folder_id,''found_folder_id''); + found_folder_id := content_item__get_id('grandpa/pa/me', -100, 'f'); + PERFORM content_test__save_val (found_folder_id,'found_folder_id'); - PERFORM content_test__put_line(''-------------------------------------''); - PERFORM content_test__put_line(''LOCATING CONTENT FOLDERS AND ITEMS...''); - PERFORM content_test__put_line(''...all tests passed!''); - PERFORM content_test__put_line(''Found me at grandpa/pa/me: '' || + PERFORM content_test__put_line('-------------------------------------'); + PERFORM content_test__put_line('LOCATING CONTENT FOLDERS AND ITEMS...'); + PERFORM content_test__put_line('...all tests passed!'); + PERFORM content_test__put_line('Found me at grandpa/pa/me: ' || found_folder_id ); - PERFORM content_test__put_line(''Path for '' || found_folder_id || '' is '' + PERFORM content_test__put_line('Path for ' || found_folder_id || ' is ' || content_item__get_path(found_folder_id,null) ); - PERFORM content_test__put_line(''Path for puppy '' || item_id || '' is '' + PERFORM content_test__put_line('Path for puppy ' || item_id || ' is ' || content_item__get_path(item_id,null) ); - PERFORM content_test__put_line(''Path for puppy '' || item_id || - '' from folder_id: '' || folder_id || - '' is '' || + PERFORM content_test__put_line('Path for puppy ' || item_id || + ' from folder_id: ' || folder_id || + ' is ' || content_item__get_path(item_id,folder_id) ); - PERFORM content_test__put_line(''Path for puppy '' || item_id || - '' from sub_folder_id: '' || - sub_folder_id || '' is '' || + PERFORM content_test__put_line('Path for puppy ' || item_id || + ' from sub_folder_id: ' || + sub_folder_id || ' is ' || content_item__get_path(item_id, sub_folder_id ) ); - PERFORM content_test__put_line(''Path for puppy '' || item_id - || '' from sub_sub_folder_id: '' || - sub_sub_folder_id || '' is '' || + PERFORM content_test__put_line('Path for puppy ' || item_id + || ' from sub_sub_folder_id: ' || + sub_sub_folder_id || ' is ' || content_item__get_path(item_id, sub_sub_folder_id ) ); - PERFORM content_test__put_line(''Get id of item with invalid path - shouldn''''t return anything''); - PERFORM content_test__put_line(''Found item at '' || - coalesce(content_item__get_id(''grandpa/me'', -200,''f'')::varchar,''null'') + PERFORM content_test__put_line('Get id of item with invalid path - shouldn''t return anything'); + PERFORM content_test__put_line('Found item at ' || + coalesce(content_item__get_id('grandpa/me', -200,'f')::varchar,'null') ); - PERFORM content_test__put_line(''Get id of item using subpath''); - PERFORM content_test__put_line(''Found item at '' || - content_item__get_id(''pa/me/puppy'', + PERFORM content_test__put_line('Get id of item using subpath'); + PERFORM content_test__put_line('Found item at ' || + content_item__get_id('pa/me/puppy', folder_id, - ''f'' + 'f' ) ); - PERFORM content_test__put_line(''This is the path to a folder from a subfolder''); - PERFORM content_test__put_line(''Path for '' || sub_folder_id || - '' from sub_sub_folder_id: '' || - sub_sub_folder_id || '' is '' || + PERFORM content_test__put_line('This is the path to a folder from a subfolder'); + PERFORM content_test__put_line('Path for ' || sub_folder_id || + ' from sub_sub_folder_id: ' || + sub_sub_folder_id || ' is ' || content_item__get_path(sub_folder_id, sub_sub_folder_id ) ); - PERFORM content_test__put_line(''This is a path to an item from a non-existant item''); - PERFORM content_test__put_line(''Path for '' || item_id || - '' from nonexistant_id: '' || - -300 || '' is '' || + PERFORM content_test__put_line('This is a path to an item from a non-existant item'); + PERFORM content_test__put_line('Path for ' || item_id || + ' from nonexistant_id: ' || + -300 || ' is ' || content_item__get_path(item_id,-300) ); - PERFORM content_test__put_line(''This is a path to an item from a non-related branch''); - PERFORM content_test__put_line(''Path for '' || item_id || - '' from unrelated branch: '' || - folder_b_id || '' is '' || + PERFORM content_test__put_line('This is a path to an item from a non-related branch'); + PERFORM content_test__put_line('Path for ' || item_id || + ' from unrelated branch: ' || + folder_b_id || ' is ' || content_item__get_path(item_id,folder_b_id) ); return null; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create function content_test__check1() returns integer as ' -declare + + +-- +-- procedure content_test__check1/0 +-- +CREATE OR REPLACE FUNCTION content_test__check1( + +) RETURNS integer AS $$ +DECLARE folder_id cr_folders.folder_id%TYPE; folder_b_id cr_folders.folder_id%TYPE; sub_folder_id cr_folders.folder_id%TYPE; @@ -395,22 +431,30 @@ symlink_b_id cr_symlinks.symlink_id%TYPE; found_folder_id cr_folders.folder_id%TYPE; -begin - folder_id := content_test__get_val(''folder_id''); - sub_sub_folder_id := content_test__get_val(''sub_sub_folder_id''); +BEGIN + folder_id := content_test__get_val('folder_id'); + sub_sub_folder_id := content_test__get_val('sub_sub_folder_id'); - PERFORM content_test__put_line(''-------------------------------------''); - PERFORM content_test__put_line(''MOVING/RENAMING CONTENT FOLDERS...''); - PERFORM content_test__put_line(''...all tests passed''); - PERFORM content_test__put_line(''Moving me from under pa to under grandpa''); + PERFORM content_test__put_line('-------------------------------------'); + PERFORM content_test__put_line('MOVING/RENAMING CONTENT FOLDERS...'); + PERFORM content_test__put_line('...all tests passed'); + PERFORM content_test__put_line('Moving me from under pa to under grandpa'); PERFORM content_item__move(sub_sub_folder_id, folder_id); return null; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create function content_test__check2() returns integer as ' -declare + + +-- +-- procedure content_test__check2/0 +-- +CREATE OR REPLACE FUNCTION content_test__check2( + +) RETURNS integer AS $$ +DECLARE folder_id cr_folders.folder_id%TYPE; folder_b_id cr_folders.folder_id%TYPE; sub_folder_id cr_folders.folder_id%TYPE; @@ -428,39 +472,39 @@ symlink_b_id cr_symlinks.symlink_id%TYPE; found_folder_id cr_folders.folder_id%TYPE; -begin - item_id := content_test__get_val(''item_id''); - sub_sub_folder_id := content_test__get_val(''sub_sub_folder_id''); - sub_folder_id := content_test__get_val(''sub_folder_id''); +BEGIN + item_id := content_test__get_val('item_id'); + sub_sub_folder_id := content_test__get_val('sub_sub_folder_id'); + sub_folder_id := content_test__get_val('sub_folder_id'); - PERFORM content_test__put_line(''Path for '' || item_id || '' is '' || + PERFORM content_test__put_line('Path for ' || item_id || ' is ' || content_item__get_path(item_id,null) ); - -- PERFORM content_test__put_line(''Moving grandpa to pa - this shouldn\\\'t work''); + -- PERFORM content_test__put_line('Moving grandpa to pa - this shouldn''t work'); -- PERFORM content_folder__move(folder_id, sub_folder_id); - -- PERFORM content_test__put_line(''Path for '' || item_id || '' is '' || + -- PERFORM content_test__put_line('Path for ' || item_id || ' is ' || -- content_item__get_path(item_id,null) -- ); - PERFORM content_test__put_line(''Renaming puppy to kitty...''); - PERFORM content_item__edit_name(item_id, ''kitty''); - PERFORM content_test__put_line(''Renaming me to aunty...''); - PERFORM content_folder__edit_name(sub_sub_folder_id, ''aunty'',null,null); - PERFORM content_test__put_line(''Path for '' || item_id || '' is '' || + PERFORM content_test__put_line('Renaming puppy to kitty...'); + PERFORM content_item__edit_name(item_id, 'kitty'); + PERFORM content_test__put_line('Renaming me to aunty...'); + PERFORM content_folder__edit_name(sub_sub_folder_id, 'aunty',null,null); + PERFORM content_test__put_line('Path for ' || item_id || ' is ' || content_item__get_path(item_id,null) ); - PERFORM content_test__put_line(''Renaming kitty to pa -- this should work''); - PERFORM content_item__edit_name(item_id, ''pa''); - PERFORM content_test__put_line(''Path for '' || item_id || '' is '' || + PERFORM content_test__put_line('Renaming kitty to pa -- this should work'); + PERFORM content_item__edit_name(item_id, 'pa'); + PERFORM content_test__put_line('Path for ' || item_id || ' is ' || content_item__get_path(item_id,null) ); - PERFORM content_test__put_line(''-------------------------------------''); - PERFORM content_test__put_line(''SYMLINKS...''); - PERFORM content_test__put_line(''...all tests passed''); + PERFORM content_test__put_line('-------------------------------------'); + PERFORM content_test__put_line('SYMLINKS...'); + PERFORM content_test__put_line('...all tests passed'); - symlink_a_id := content_symlink__new(''link_a'', + symlink_a_id := content_symlink__new('link_a', null, sub_sub_folder_id, sub_folder_id, @@ -470,14 +514,22 @@ null ); - PERFORM content_test__save_val (symlink_a_id,''symlink_a_id''); + PERFORM content_test__save_val (symlink_a_id,'symlink_a_id'); return null; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create function content_test__check3() returns integer as ' -declare + + +-- +-- procedure content_test__check3/0 +-- +CREATE OR REPLACE FUNCTION content_test__check3( + +) RETURNS integer AS $$ +DECLARE folder_id cr_folders.folder_id%TYPE; folder_b_id cr_folders.folder_id%TYPE; sub_folder_id cr_folders.folder_id%TYPE; @@ -495,109 +547,117 @@ symlink_b_id cr_symlinks.symlink_id%TYPE; found_folder_id cr_folders.folder_id%TYPE; -begin - folder_id := content_test__get_val(''folder_id''); - folder_b_id := content_test__get_val(''folder_b_id''); - sub_folder_id := content_test__get_val(''sub_folder_id''); - sub_sub_folder_id := content_test__get_val(''sub_sub_folder_id''); - item_id := content_test__get_val(''item_id''); - simple_item_id := content_test__get_val(''simple_item_id''); - live_revision_id := content_test__get_val(''live_revision_id''); - late_revision_id := content_test__get_val(''late_revision_id''); - item_template_id := content_test__get_val(''item_template_id''); - type_template_id := content_test__get_val(''type_template_id''); - def_type_template_id := content_test__get_val(''def_type_template_id''); - dum_template_id := content_test__get_val(''dum_template_id''); - found_folder_id := content_test__get_val(''found_folder_id''); - symlink_a_id := content_test__get_val(''symlink_a_id''); +BEGIN + folder_id := content_test__get_val('folder_id'); + folder_b_id := content_test__get_val('folder_b_id'); + sub_folder_id := content_test__get_val('sub_folder_id'); + sub_sub_folder_id := content_test__get_val('sub_sub_folder_id'); + item_id := content_test__get_val('item_id'); + simple_item_id := content_test__get_val('simple_item_id'); + live_revision_id := content_test__get_val('live_revision_id'); + late_revision_id := content_test__get_val('late_revision_id'); + item_template_id := content_test__get_val('item_template_id'); + type_template_id := content_test__get_val('type_template_id'); + def_type_template_id := content_test__get_val('def_type_template_id'); + dum_template_id := content_test__get_val('dum_template_id'); + found_folder_id := content_test__get_val('found_folder_id'); + symlink_a_id := content_test__get_val('symlink_a_id'); - PERFORM content_test__put_line(''Create a link in pa to aunty: Symlink is '' || symlink_a_id); + PERFORM content_test__put_line('Create a link in pa to aunty: Symlink is ' || symlink_a_id); - PERFORM content_test__put_line(''Is '' || symlink_a_id || '' a symlink?: '' + PERFORM content_test__put_line('Is ' || symlink_a_id || ' a symlink?: ' || cast_char(content_symlink__is_symlink(symlink_a_id)) ); - PERFORM content_test__put_line(''Is '' || folder_id || '' a symlink?: '' || + PERFORM content_test__put_line('Is ' || folder_id || ' a symlink?: ' || cast_char(content_symlink__is_symlink(folder_id)) ); - PERFORM content_test__put_line(''Path for symlink '' || symlink_a_id || - '' is '' || + PERFORM content_test__put_line('Path for symlink ' || symlink_a_id || + ' is ' || content_item__get_path(symlink_a_id,null) ); - PERFORM content_test__put_line(''Resolving symlink '' || symlink_a_id || - '' is '' || + PERFORM content_test__put_line('Resolving symlink ' || symlink_a_id || + ' is ' || content_symlink__resolve(symlink_a_id) ); - PERFORM content_test__put_line(''Resolved path for symlink '' || - symlink_a_id || '' is '' || + PERFORM content_test__put_line('Resolved path for symlink ' || + symlink_a_id || ' is ' || content_item__get_path(content_symlink__resolve(symlink_a_id),null) ); - PERFORM content_test__put_line(''Path to item '' || item_id || - '' from symlink '' || - symlink_a_id || '' is '' || + PERFORM content_test__put_line('Path to item ' || item_id || + ' from symlink ' || + symlink_a_id || ' is ' || content_item__get_path(item_id, symlink_a_id) ); - PERFORM content_test__put_line(''Path to item '' || item_id || - '' from aunty '' || - sub_sub_folder_id || '' is '' || + PERFORM content_test__put_line('Path to item ' || item_id || + ' from aunty ' || + sub_sub_folder_id || ' is ' || content_item__get_path(item_id, sub_sub_folder_id) ); - PERFORM content_test__put_line(''Path to pa '' || sub_folder_id || - '' from symlink '' || - symlink_a_id || '' is '' || + PERFORM content_test__put_line('Path to pa ' || sub_folder_id || + ' from symlink ' || + symlink_a_id || ' is ' || content_item__get_path(sub_folder_id, symlink_a_id ) ); - PERFORM content_test__put_line(''Found item '' || item_id || '' at '' || - content_item__get_id(''/grandpa/aunty/pa'',null,''f'') + PERFORM content_test__put_line('Found item ' || item_id || ' at ' || + content_item__get_id('/grandpa/aunty/pa',null,'f') ); - PERFORM content_test__put_line(''Found item '' || item_id || '' at '' || - content_item__get_id(''/grandpa/pa/link_a/pa'',null,''f'') + PERFORM content_test__put_line('Found item ' || item_id || ' at ' || + content_item__get_id('/grandpa/pa/link_a/pa',null,'f') ); - PERFORM content_test__put_line(''Found item '' || item_id || - '' starting at aunty '' || - sub_sub_folder_id || '' at '' || - content_item__get_id(''pa'', + PERFORM content_test__put_line('Found item ' || item_id || + ' starting at aunty ' || + sub_sub_folder_id || ' at ' || + content_item__get_id('pa', sub_sub_folder_id, - ''f'' + 'f' ) ); - PERFORM content_test__put_line(''Found item '' || item_id || - '' starting at symlink '' || - symlink_a_id || '' at '' || - content_item__get_id(''pa'',symlink_a_id,''f'') + PERFORM content_test__put_line('Found item ' || item_id || + ' starting at symlink ' || + symlink_a_id || ' at ' || + content_item__get_id('pa',symlink_a_id,'f') ); - PERFORM content_test__put_line(''Found item '' || item_id || - '' starting at pa '' || - sub_folder_id || '' at '' || - content_item__get_id(''link_a/bunny'', + PERFORM content_test__put_line('Found item ' || item_id || + ' starting at pa ' || + sub_folder_id || ' at ' || + content_item__get_id('link_a/bunny', sub_folder_id, - ''f'' + 'f' ) ); - PERFORM content_test__put_line(''--------------------------------''); + PERFORM content_test__put_line('--------------------------------'); - PERFORM content_test__put_line(''Moving item '' || item_id || - '' to grandma '' || + PERFORM content_test__put_line('Moving item ' || item_id || + ' to grandma ' || folder_b_id ); PERFORM content_item__move(item_id,folder_b_id); return null; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create function content_test__check4() returns integer as ' -declare + + +-- +-- procedure content_test__check4/0 +-- +CREATE OR REPLACE FUNCTION content_test__check4( + +) RETURNS integer AS $$ +DECLARE folder_id cr_folders.folder_id%TYPE; folder_b_id cr_folders.folder_id%TYPE; sub_folder_id cr_folders.folder_id%TYPE; @@ -615,26 +675,34 @@ symlink_b_id cr_symlinks.symlink_id%TYPE; found_folder_id cr_folders.folder_id%TYPE; -begin - item_id := content_test__get_val(''item_id''); - folder_b_id := content_test__get_val(''folder_b_id''); - sub_sub_folder_id := content_test__get_val(''sub_sub_folder_id''); +BEGIN + item_id := content_test__get_val('item_id'); + folder_b_id := content_test__get_val('folder_b_id'); + sub_sub_folder_id := content_test__get_val('sub_sub_folder_id'); - PERFORM content_test__put_line(''Path for item '' || item_id || '' is '' || + PERFORM content_test__put_line('Path for item ' || item_id || ' is ' || content_item__get_path(item_id,null) ); - PERFORM content_test__put_line(''Moving folder '' || folder_b_id || - '' to aunty '' || sub_sub_folder_id + PERFORM content_test__put_line('Moving folder ' || folder_b_id || + ' to aunty ' || sub_sub_folder_id ); PERFORM content_item__move(folder_b_id,sub_sub_folder_id); return null; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create function content_test__check5() returns integer as ' -declare + + +-- +-- procedure content_test__check5/0 +-- +CREATE OR REPLACE FUNCTION content_test__check5( + +) RETURNS integer AS $$ +DECLARE folder_id cr_folders.folder_id%TYPE; folder_b_id cr_folders.folder_id%TYPE; sub_folder_id cr_folders.folder_id%TYPE; @@ -652,26 +720,26 @@ symlink_b_id cr_symlinks.symlink_id%TYPE; found_folder_id cr_folders.folder_id%TYPE; -begin - folder_id := content_test__get_val(''folder_id''); - folder_b_id := content_test__get_val(''folder_b_id''); - sub_folder_id := content_test__get_val(''sub_folder_id''); - sub_sub_folder_id := content_test__get_val(''sub_sub_folder_id''); - item_id := content_test__get_val(''item_id''); - simple_item_id := content_test__get_val(''simple_item_id''); - live_revision_id := content_test__get_val(''live_revision_id''); - late_revision_id := content_test__get_val(''late_revision_id''); - item_template_id := content_test__get_val(''item_template_id''); - type_template_id := content_test__get_val(''type_template_id''); - def_type_template_id := content_test__get_val(''def_type_template_id''); - dum_template_id := content_test__get_val(''dum_template_id''); - found_folder_id := content_test__get_val(''found_folder_id''); +BEGIN + folder_id := content_test__get_val('folder_id'); + folder_b_id := content_test__get_val('folder_b_id'); + sub_folder_id := content_test__get_val('sub_folder_id'); + sub_sub_folder_id := content_test__get_val('sub_sub_folder_id'); + item_id := content_test__get_val('item_id'); + simple_item_id := content_test__get_val('simple_item_id'); + live_revision_id := content_test__get_val('live_revision_id'); + late_revision_id := content_test__get_val('late_revision_id'); + item_template_id := content_test__get_val('item_template_id'); + type_template_id := content_test__get_val('type_template_id'); + def_type_template_id := content_test__get_val('def_type_template_id'); + dum_template_id := content_test__get_val('dum_template_id'); + found_folder_id := content_test__get_val('found_folder_id'); - PERFORM content_test__put_line(''Path for item '' || item_id || '' is '' || + PERFORM content_test__put_line('Path for item ' || item_id || ' is ' || content_item__get_path(item_id,null) ); - PERFORM content_test__put_line(''--------------------------------''); + PERFORM content_test__put_line('--------------------------------'); -- symlinks/revisions should be deleted automatically @@ -688,7 +756,8 @@ return null; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; \t select content_test__create(); Index: openacs-4/packages/acs-content-repository/sql/postgresql/content-type.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/sql/postgresql/content-type.sql,v diff -u -r1.55 -r1.56 --- openacs-4/packages/acs-content-repository/sql/postgresql/content-type.sql 20 Feb 2011 00:34:00 -0000 1.55 +++ openacs-4/packages/acs-content-repository/sql/postgresql/content-type.sql 7 Jul 2011 10:46:02 -0000 1.56 @@ -14,57 +14,68 @@ -- Create a trigger to make sure that there will never be more than -- one default template for a given content type and use context -create function cr_type_template_map_tr () returns opaque as ' -begin +CREATE OR REPLACE FUNCTION cr_type_template_map_tr () RETURNS trigger AS $$ +BEGIN - if new.is_default = ''t'' then + if new.is_default = 't' then update cr_type_template_map set - is_default = ''f'' + is_default = 'f' where content_type = new.content_type and use_context = new.use_context and template_id <> new.template_id and - is_default = ''t''; + is_default = 't'; end if; return new; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; create trigger cr_type_template_map_tr before insert on cr_type_template_map for each row execute procedure cr_type_template_map_tr (); -select define_function_args('content_type__create_type','content_type,supertype;content_revision,pretty_name,pretty_plural,table_name,id_column,name_method'); -create or replace function content_type__create_type (varchar,varchar,varchar,varchar,varchar,varchar,varchar) -returns integer as ' -declare - create_type__content_type alias for $1; - create_type__supertype alias for $2; -- default ''content_revision'' - create_type__pretty_name alias for $3; - create_type__pretty_plural alias for $4; - create_type__table_name alias for $5; - create_type__id_column alias for $6; -- default ''XXX'' - create_type__name_method alias for $7; -- default null +-- old define_function_args('content_type__create_type','content_type,supertype;content_revision,pretty_name,pretty_plural,table_name,id_column,name_method') +-- new +select define_function_args('content_type__create_type','content_type,supertype;content_revision,pretty_name,pretty_plural,table_name,id_column;XXX,name_method;null'); + + + + +-- +-- procedure content_type__create_type/7 +-- +CREATE OR REPLACE FUNCTION content_type__create_type( + create_type__content_type varchar, + create_type__supertype varchar, -- default 'content_revision' + create_type__pretty_name varchar, + create_type__pretty_plural varchar, + create_type__table_name varchar, + create_type__id_column varchar, -- default 'XXX' + create_type__name_method varchar -- default null + +) RETURNS integer AS $$ +DECLARE v_temp_p boolean; v_supertype_table acs_object_types.table_name%TYPE; -begin +BEGIN - if (create_type__supertype <> ''content_revision'') - and (create_type__content_type <> ''content_revision'') then + if (create_type__supertype <> 'content_revision') + and (create_type__content_type <> 'content_revision') then select count(*) > 0 into v_temp_p from acs_object_type_supertype_map where object_type = create_type__supertype - and ancestor_type = ''content_revision''; + and ancestor_type = 'content_revision'; if not v_temp_p then - raise EXCEPTION ''-20000: supertype % must be a subtype of content_revision'', create_type__supertype; + raise EXCEPTION '-20000: supertype % must be a subtype of content_revision', create_type__supertype; end if; end if; @@ -80,37 +91,48 @@ create_type__table_name, create_type__id_column, null, - ''f'', + 'f', null, create_type__name_method, v_temp_p, - ''f'' + 'f' ); PERFORM content_type__refresh_view(create_type__content_type); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; + +-- old define_function_args('content_type__drop_type','content_type,drop_children_p;f,drop_table_p;f,drop_objects_p;f') +-- new select define_function_args('content_type__drop_type','content_type,drop_children_p;f,drop_table_p;f,drop_objects_p;f'); -create or replace function content_type__drop_type (varchar,boolean,boolean,boolean) -returns integer as ' -declare - drop_type__content_type alias for $1; - drop_type__drop_children_p alias for $2; -- default ''f'' - drop_type__drop_table_p alias for $3; -- default ''f'' - drop_type__drop_objects_p alias for $4; -- default ''f'' + + + +-- +-- procedure content_type__drop_type/4 +-- +CREATE OR REPLACE FUNCTION content_type__drop_type( + drop_type__content_type varchar, + drop_type__drop_children_p boolean, -- default 'f' + drop_type__drop_table_p boolean, -- default 'f' + drop_type__drop_objects_p boolean -- default 'f' + +) RETURNS integer AS $$ +DECLARE table_exists_p boolean; v_table_name varchar; is_subclassed_p boolean; child_rec record; attr_row record; revision_row record; item_row record; -begin +BEGIN - -- first we''ll rid ourselves of any dependent child types, if any , + -- first we'll rid ourselves of any dependent child types, if any , -- along with their own dependent grandchild types select @@ -122,7 +144,7 @@ -- this is weak and will probably break; -- to remove grand child types, the process will probably -- require some sort of querying for drop_type - -- methods within the children''s packages to make + -- methods within the children's packages to make -- certain there are no additional unanticipated -- restraints preventing a clean drop @@ -135,7 +157,7 @@ where supertype = drop_type__content_type LOOP - PERFORM content_type__drop_type(child_rec.object_type, ''t'', drop_type__drop_table_p, drop_type__drop_objects_p); + PERFORM content_type__drop_type(child_rec.object_type, 't', drop_type__drop_table_p, drop_type__drop_objects_p); end LOOP; end if; @@ -150,11 +172,11 @@ LOOP PERFORM content_type__drop_attribute(drop_type__content_type, attr_row.attribute_name, - ''f'' + 'f' ); end LOOP; - -- we''ll remove the associated table if it exists + -- we'll remove the associated table if it exists select table_exists(lower(table_name)) into table_exists_p from @@ -180,7 +202,7 @@ -- different syntax for dropping a rule in 7.2 and 7.3 so check which -- version is being used (olah). - execute ''drop table '' || v_table_name || '' cascade''; + execute 'drop table ' || v_table_name || ' cascade'; end if; @@ -209,25 +231,36 @@ PERFORM acs_object_type__drop_type(drop_type__content_type, drop_type__drop_objects_p); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- don't define function_args twice --- select define_function_args('content_type__drop_type','content_type,drop_children_p;f,drop_table_p;f'); +-- +-- old define_function_args('content_type__drop_type','content_type,drop_children_p;f,drop_table_p;f') +-- new +select define_function_args('content_type__drop_type','content_type,drop_children_p;f,drop_table_p;f,drop_objects_p;f'); -create or replace function content_type__drop_type (varchar,boolean,boolean) -returns integer as ' -declare - drop_type__content_type alias for $1; - drop_type__drop_children_p alias for $2; -- default ''f'' - drop_type__drop_table_p alias for $3; -- default ''f'' + + + +-- +-- procedure content_type__drop_type/3 +-- +CREATE OR REPLACE FUNCTION content_type__drop_type( + drop_type__content_type varchar, + drop_type__drop_children_p boolean, -- default 'f' + drop_type__drop_table_p boolean -- default 'f' + +) RETURNS integer AS $$ +DECLARE table_exists_p boolean; v_table_name varchar; is_subclassed_p boolean; child_rec record; attr_row record; -begin +BEGIN - -- first we''ll rid ourselves of any dependent child types, if any , + -- first we'll rid ourselves of any dependent child types, if any , -- along with their own dependent grandchild types select @@ -239,7 +272,7 @@ -- this is weak and will probably break; -- to remove grand child types, the process will probably -- require some sort of querying for drop_type - -- methods within the children''s packages to make + -- methods within the children's packages to make -- certain there are no additional unanticipated -- restraints preventing a clean drop @@ -252,7 +285,7 @@ where supertype = drop_type__content_type LOOP - PERFORM content_type__drop_type(child_rec.object_type, ''t'', ''f''); + PERFORM content_type__drop_type(child_rec.object_type, 't', 'f'); end LOOP; end if; @@ -267,11 +300,11 @@ LOOP PERFORM content_type__drop_attribute(drop_type__content_type, attr_row.attribute_name, - ''f'' + 'f' ); end LOOP; - -- we''ll remove the associated table if it exists + -- we'll remove the associated table if it exists select table_exists(lower(table_name)) into table_exists_p from @@ -294,52 +327,54 @@ -- The rule dropping might be redundant as the rule might be dropped -- when the view is dropped. - -- different syntax for dropping a rule in 7.2 and 7.3 so check which - -- version is being used (olah). + execute 'drop rule ' || v_table_name || '_r ' || 'on ' || v_table_name || 'i'; + execute 'drop view ' || v_table_name || 'x cascade'; + execute 'drop view ' || v_table_name || 'i cascade'; - if version() like ''%PostgreSQL 7.2%'' then - execute ''drop rule '' || v_table_name || ''_r''; - else - -- 7.3 syntax - execute ''drop rule '' || v_table_name || ''_r '' || ''on '' || v_table_name || ''i''; - end if; - - execute ''drop view '' || v_table_name || ''x cascade''; - execute ''drop view '' || v_table_name || ''i cascade''; - - execute ''drop table '' || v_table_name; + execute 'drop table ' || v_table_name; end if; - PERFORM acs_object_type__drop_type(drop_type__content_type, ''f''); + PERFORM acs_object_type__drop_type(drop_type__content_type, 'f'); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -select define_function_args('content_type__create_attribute','content_type,attribute_name,datatype,pretty_name,pretty_plural,sort_order,default_value,column_spec;text'); -create or replace function content_type__create_attribute (varchar,varchar,varchar,varchar,varchar,integer,varchar,varchar) -returns integer as ' -declare - create_attribute__content_type alias for $1; - create_attribute__attribute_name alias for $2; - create_attribute__datatype alias for $3; - create_attribute__pretty_name alias for $4; - create_attribute__pretty_plural alias for $5; -- default null - create_attribute__sort_order alias for $6; -- default null - create_attribute__default_value alias for $7; -- default null - create_attribute__column_spec alias for $8; -- default ''text'' +-- old define_function_args('content_type__create_attribute','content_type,attribute_name,datatype,pretty_name,pretty_plural,sort_order,default_value,column_spec;text') +-- new +select define_function_args('content_type__create_attribute','content_type,attribute_name,datatype,pretty_name,pretty_plural;null,sort_order;null,default_value;null,column_spec;text'); + + + + +-- +-- procedure content_type__create_attribute/8 +-- +CREATE OR REPLACE FUNCTION content_type__create_attribute( + create_attribute__content_type varchar, + create_attribute__attribute_name varchar, + create_attribute__datatype varchar, + create_attribute__pretty_name varchar, + create_attribute__pretty_plural varchar, -- default null + create_attribute__sort_order integer, -- default null + create_attribute__default_value varchar, -- default null + create_attribute__column_spec varchar -- default 'text' + +) RETURNS integer AS $$ +DECLARE v_attr_id acs_attributes.attribute_id%TYPE; v_table_name acs_object_types.table_name%TYPE; v_column_exists boolean; -begin +BEGIN -- add the appropriate column to the table select table_name into v_table_name from acs_object_types where object_type = create_attribute__content_type; if NOT FOUND then - raise EXCEPTION ''-20000: Content type % does not exist in content_type.create_attribute'', create_attribute__content_type; + raise EXCEPTION '-20000: Content type % does not exist in content_type.create_attribute', create_attribute__content_type; end if; select count(*) > 0 into v_column_exists @@ -360,8 +395,8 @@ 1, 1, create_attribute__sort_order, - ''type_specific'', - ''f'', + 'type_specific', + 'f', not v_column_exists, null, null, @@ -375,19 +410,26 @@ return v_attr_id; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select define_function_args('content_type__drop_attribute','content_type,attribute_name,drop_column;f'); -create or replace function content_type__drop_attribute (varchar,varchar,boolean) -returns integer as ' -declare - drop_attribute__content_type alias for $1; - drop_attribute__attribute_name alias for $2; - drop_attribute__drop_column alias for $3; -- default ''f'' + + +-- +-- procedure content_type__drop_attribute/3 +-- +CREATE OR REPLACE FUNCTION content_type__drop_attribute( + drop_attribute__content_type varchar, + drop_attribute__attribute_name varchar, + drop_attribute__drop_column boolean -- default 'f' + +) RETURNS integer AS $$ +DECLARE v_attr_id acs_attributes.attribute_id%TYPE; v_table acs_object_types.table_name%TYPE; -begin +BEGIN -- Get attribute information select @@ -404,7 +446,7 @@ a.attribute_name = drop_attribute__attribute_name; if NOT FOUND then - raise EXCEPTION ''-20000: Attribute %:% does not exist in content_type.drop_attribute'', drop_attribute__content_type, drop_attribute__attribute_name; + raise EXCEPTION '-20000: Attribute %:% does not exist in content_type.drop_attribute', drop_attribute__content_type, drop_attribute__attribute_name; end if; -- Drop the attribute @@ -414,27 +456,34 @@ -- FIXME: postgresql does not support drop column. -- Drop the column if neccessary if drop_attribute__drop_column then - execute ''alter table '' || v_table || '' drop column '' || - drop_attribute__attribute_name || '' cascade''; + execute 'alter table ' || v_table || ' drop column ' || + drop_attribute__attribute_name || ' cascade'; end if; PERFORM content_type__refresh_view(drop_attribute__content_type); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select define_function_args('content_type__register_template','content_type,template_id,use_context,is_default;f'); -create or replace function content_type__register_template (varchar,integer,varchar,boolean) -returns integer as ' -declare - register_template__content_type alias for $1; - register_template__template_id alias for $2; - register_template__use_context alias for $3; - register_template__is_default alias for $4; -- default ''f'' + + +-- +-- procedure content_type__register_template/4 +-- +CREATE OR REPLACE FUNCTION content_type__register_template( + register_template__content_type varchar, + register_template__template_id integer, + register_template__use_context varchar, + register_template__is_default boolean -- default 'f' + +) RETURNS integer AS $$ +DECLARE v_template_registered boolean; -begin +BEGIN select count(*) > 0 into v_template_registered from @@ -461,7 +510,7 @@ -- unset the default template before setting this one as the default if register_template__is_default then update cr_type_template_map - set is_default = ''f'' + set is_default = 'f' where content_type = register_template__content_type and use_context = register_template__use_context; end if; @@ -474,47 +523,59 @@ end if; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select define_function_args('content_type__set_default_template','content_type,template_id,use_context'); -create or replace function content_type__set_default_template (varchar,integer,varchar) -returns integer as ' -declare - set_default_template__content_type alias for $1; - set_default_template__template_id alias for $2; - set_default_template__use_context alias for $3; + + +-- +-- procedure content_type__set_default_template/3 +-- +CREATE OR REPLACE FUNCTION content_type__set_default_template( + set_default_template__content_type varchar, + set_default_template__template_id integer, + set_default_template__use_context varchar +) RETURNS integer AS $$ +DECLARE -begin +BEGIN update cr_type_template_map - set is_default = ''t'' + set is_default = 't' where template_id = set_default_template__template_id and content_type = set_default_template__content_type and use_context = set_default_template__use_context; -- make sure there is only one default template for -- any given content_type/use_context pair update cr_type_template_map - set is_default = ''f'' + set is_default = 'f' where template_id <> set_default_template__template_id and content_type = set_default_template__content_type and use_context = set_default_template__use_context - and is_default = ''t''; + and is_default = 't'; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select define_function_args('content_type__get_template','content_type,use_context'); -create or replace function content_type__get_template (varchar,varchar) -returns integer as ' -declare - get_template__content_type alias for $1; - get_template__use_context alias for $2; + + +-- +-- procedure content_type__get_template/2 +-- +CREATE OR REPLACE FUNCTION content_type__get_template( + get_template__content_type varchar, + get_template__use_context varchar +) RETURNS integer AS $$ +DECLARE v_template_id cr_templates.template_id%TYPE; -begin +BEGIN select template_id into @@ -526,23 +587,34 @@ and use_context = get_template__use_context and - is_default = ''t''; + is_default = 't'; return v_template_id; -end;' language 'plpgsql' stable strict; +END; +$$ LANGUAGE plpgsql stable strict; -select define_function_args('content_type__unregister_template','content_type,template_id,use_context'); -create or replace function content_type__unregister_template (varchar,integer,varchar) -returns integer as ' -declare - unregister_template__content_type alias for $1; -- default null - unregister_template__template_id alias for $2; - unregister_template__use_context alias for $3; -- default null -begin +-- old define_function_args('content_type__unregister_template','content_type,template_id,use_context') +-- new +select define_function_args('content_type__unregister_template','content_type;null,template_id,use_context;null'); + + + +-- +-- procedure content_type__unregister_template/3 +-- +CREATE OR REPLACE FUNCTION content_type__unregister_template( + unregister_template__content_type varchar, -- default null + unregister_template__template_id integer, + unregister_template__use_context varchar -- default null + +) RETURNS integer AS $$ +DECLARE +BEGIN + if unregister_template__use_context is null and unregister_template__content_type is null then @@ -571,23 +643,29 @@ end if; end if; end if; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function trigger_insert_statement select define_function_args('content_type__trigger_insert_statement','content_type'); -create or replace function content_type__trigger_insert_statement (varchar) -returns varchar as ' -declare - trigger_insert_statement__content_type alias for $1; + + +-- +-- procedure content_type__trigger_insert_statement/1 +-- +CREATE OR REPLACE FUNCTION content_type__trigger_insert_statement( + trigger_insert_statement__content_type varchar +) RETURNS varchar AS $$ +DECLARE v_table_name acs_object_types.table_name%TYPE; v_id_column acs_object_types.id_column%TYPE; - cols varchar default ''''; - vals varchar default ''''; + cols varchar default ''; + vals varchar default ''; attr_rec record; -begin +BEGIN if trigger_insert_statement__content_type is null then - return exception ''content_type__trigger_insert_statement called with null content_type''; + return exception 'content_type__trigger_insert_statement called with null content_type'; end if; select @@ -604,15 +682,16 @@ where object_type = trigger_insert_statement__content_type LOOP - cols := cols || '', '' || attr_rec.attribute_name; - vals := vals || '', p_new.'' || attr_rec.attribute_name; + cols := cols || ', ' || attr_rec.attribute_name; + vals := vals || ', p_new.' || attr_rec.attribute_name; end LOOP; - return ''insert into '' || v_table_name || - '' ( '' || v_id_column || cols || '' ) values (v_revision_id'' || - vals || '')''; + return 'insert into ' || v_table_name || + ' ( ' || v_id_column || cols || ' ) values (v_revision_id' || + vals || ')'; -end;' language 'plpgsql' stable; +END; +$$ LANGUAGE plpgsql stable; -- FIXME: need to look at this in more detail. This probably can't be made -- to work reliably in postgresql. Currently we are using a rule to insert @@ -634,18 +713,23 @@ select define_function_args('content_type__refresh_trigger','content_type'); -create or replace function content_type__refresh_trigger (varchar) -returns integer as ' -declare - refresh_trigger__content_type alias for $1; - rule_text text default ''''; - function_text text default ''''; + + +-- +-- procedure content_type__refresh_trigger/1 +-- +CREATE OR REPLACE FUNCTION content_type__refresh_trigger( + refresh_trigger__content_type varchar +) RETURNS integer AS $$ +DECLARE + rule_text text default ''; + function_text text default ''; v_table_name acs_object_types.table_name%TYPE; type_rec record; -begin +BEGIN -- get the table name for the content type (determines view name) - raise NOTICE ''refresh trigger for % '', refresh_trigger__content_type; + raise NOTICE 'refresh trigger for % ', refresh_trigger__content_type; -- Since we allow null table name use object type if table name is null so -- we still can have a view. @@ -657,8 +741,8 @@ --=================== start building rule code ======================= function_text := function_text || - ''create or replace function '' || v_table_name || ''_f (p_new ''|| v_table_name || ''i) - returns void as '''' + 'create or replace function ' || v_table_name || '_f (p_new '|| v_table_name || 'i) + returns void as '' declare v_revision_id integer; begin @@ -680,85 +764,82 @@ p_new.creation_ip, p_new.object_package_id ) into v_revision_id; - ''; + '; -- add an insert statement for each subtype in the hierarchy for this type for type_rec in select ot2.object_type, tree_level(ot2.tree_sortkey) as level from acs_object_types ot1, acs_object_types ot2 - where ot2.object_type <> ''acs_object'' - and ot2.object_type <> ''content_revision'' + where ot2.object_type <> 'acs_object' + and ot2.object_type <> 'content_revision' and ot1.object_type = refresh_trigger__content_type and ot1.tree_sortkey between ot2.tree_sortkey and tree_right(ot2.tree_sortkey) and ot1.table_name is not null order by level asc LOOP - function_text := function_text || '' '' || content_type__trigger_insert_statement(type_rec.object_type) || ''; - ''; + function_text := function_text || ' ' || content_type__trigger_insert_statement(type_rec.object_type) || '; + '; end loop; - function_text := function_text || '' + function_text := function_text || ' return; - end;'''' language ''''plpgsql''''; - ''; + end;'' language ''plpgsql''; + '; -- end building the rule definition code -- create the new function execute function_text; - rule_text := ''create rule '' || v_table_name || ''_r as on insert to '' || - v_table_name || ''i do instead SELECT '' || v_table_name || ''_f(new); '' ; + rule_text := 'create rule ' || v_table_name || '_r as on insert to ' || + v_table_name || 'i do instead SELECT ' || v_table_name || '_f(new); ' ; --================== done building rule code ======================= -- drop the old rule - if rule_exists(v_table_name || ''_r'', v_table_name || ''i'') then - - -- different syntax for dropping a rule in 7.2 and 7.3 so check which - -- version is being used (olah). - if version() like ''%PostgreSQL 7.2%'' then - execute ''drop rule '' || v_table_name || ''_r''; - else - -- 7.3 syntax - execute ''drop rule '' || v_table_name || ''_r '' || ''on '' || v_table_name || ''i''; - end if; - + if rule_exists(v_table_name || '_r', v_table_name || 'i') then + execute 'drop rule ' || v_table_name || '_r ' || 'on ' || v_table_name || 'i'; end if; -- create the new rule for inserts on the content type execute rule_text; return null; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select define_function_args('content_type__refresh_view','content_type'); -create or replace function content_type__refresh_view (varchar) -returns integer as ' -declare - refresh_view__content_type alias for $1; - cols varchar default ''''; - tabs varchar default ''''; - joins varchar default ''''; + + +-- +-- procedure content_type__refresh_view/1 +-- +CREATE OR REPLACE FUNCTION content_type__refresh_view( + refresh_view__content_type varchar +) RETURNS integer AS $$ +DECLARE + cols varchar default ''; + tabs varchar default ''; + joins varchar default ''; v_table_name varchar; join_rec record; -begin +BEGIN for join_rec in select ot2.table_name, ot2.id_column, tree_level(ot2.tree_sortkey) as level from acs_object_types ot1, acs_object_types ot2 - where ot2.object_type <> ''acs_object'' - and ot2.object_type <> ''content_revision'' - and lower(ot2.table_name) <> ''acs_objects'' - and lower(ot2.table_name) <> ''cr_revisions'' + where ot2.object_type <> 'acs_object' + and ot2.object_type <> 'content_revision' + and lower(ot2.table_name) <> 'acs_objects' + and lower(ot2.table_name) <> 'cr_revisions' and ot1.object_type = refresh_view__content_type and ot1.tree_sortkey between ot2.tree_sortkey and tree_right(ot2.tree_sortkey) order by ot2.tree_sortkey desc LOOP if join_rec.table_name is not null then - cols := cols || '', '' || join_rec.table_name || ''.*''; - tabs := tabs || '', '' || join_rec.table_name; - joins := joins || '' and acs_objects.object_id = '' || - join_rec.table_name || ''.'' || join_rec.id_column; + cols := cols || ', ' || join_rec.table_name || '.*'; + tabs := tabs || ', ' || join_rec.table_name; + joins := joins || ' and acs_objects.object_id = ' || + join_rec.table_name || '.' || join_rec.id_column; end if; end loop; @@ -768,21 +849,21 @@ where object_type = refresh_view__content_type; if length(v_table_name) > 57 then - raise exception ''Table name cannot be longer than 57 characters, because that causes conflicting rules when we create the views.''; + raise exception 'Table name cannot be longer than 57 characters, because that causes conflicting rules when we create the views.'; end if; -- create the input view (includes content columns) - if table_exists(v_table_name || ''i'') then - execute ''drop view '' || v_table_name || ''i'' || '' CASCADE''; + if table_exists(v_table_name || 'i') then + execute 'drop view ' || v_table_name || 'i' || ' CASCADE'; end if; -- FIXME: need to look at content_revision__get_content. Since the CR -- can store data in a lob, a text field or in an external file, getting -- the data attribute for this view will be problematic. - execute ''create view '' || v_table_name || - ''i as select acs_objects.object_id, + execute 'create view ' || v_table_name || + 'i as select acs_objects.object_id, acs_objects.object_type, acs_objects.title as object_title, acs_objects.package_id as object_package_id, @@ -798,19 +879,19 @@ acs_objects.max_child_sortkey, cr.revision_id, cr.title, cr.item_id, content_revision__get_content(cr.revision_id) as data, cr_text.text_data as text, - cr.description, cr.publish_date, cr.mime_type, cr.nls_language'' || + cr.description, cr.publish_date, cr.mime_type, cr.nls_language' || cols || - '' from acs_objects, cr_revisions cr, cr_text'' || tabs || '' where - acs_objects.object_id = cr.revision_id '' || joins; + ' from acs_objects, cr_revisions cr, cr_text' || tabs || ' where + acs_objects.object_id = cr.revision_id ' || joins; -- create the output view (excludes content columns to enable SELECT *) - if table_exists(v_table_name || ''x'') then - execute ''drop view '' || v_table_name || ''x cascade''; + if table_exists(v_table_name || 'x') then + execute 'drop view ' || v_table_name || 'x cascade'; end if; - execute ''create view '' || v_table_name || - ''x as select acs_objects.object_id, + execute 'create view ' || v_table_name || + 'x as select acs_objects.object_id, acs_objects.object_type, acs_objects.title as object_title, acs_objects.package_id as object_package_id, @@ -825,36 +906,51 @@ acs_objects.tree_sortkey, acs_objects.max_child_sortkey, cr.revision_id, cr.title, cr.item_id, cr.description, cr.publish_date, cr.mime_type, cr.nls_language, - i.name, i.parent_id'' || + i.name, i.parent_id' || cols || - '' from acs_objects, cr_revisions cr, cr_items i, cr_text'' || tabs || - '' where acs_objects.object_id = cr.revision_id - and cr.item_id = i.item_id'' || joins; + ' from acs_objects, cr_revisions cr, cr_items i, cr_text' || tabs || + ' where acs_objects.object_id = cr.revision_id + and cr.item_id = i.item_id' || joins; PERFORM content_type__refresh_trigger(refresh_view__content_type); -- exception -- when others then --- dbms_output.put_line(''Error creating attribute view or trigger for'' +-- dbms_output.put_line('Error creating attribute view or trigger for' -- || content_type); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -select define_function_args('content_type__register_child_type','parent_type,child_type,relation_tag;generic,min_n;0,max_n'); +-- old define_function_args('content_type__register_child_type','parent_type,child_type,relation_tag;generic,min_n;0,max_n') +-- new +select define_function_args('content_type__register_child_type','parent_type,child_type,relation_tag;generic,min_n;0,max_n;null'); + + -- procedure register_child_type -select define_function_args('content_type__register_child_type','parent_type,child_type,relation_tag;generic,min_n;0,max_n'); -create or replace function content_type__register_child_type (varchar,varchar,varchar,integer,integer) -returns integer as ' -declare - register_child_type__parent_type alias for $1; - register_child_type__child_type alias for $2; - register_child_type__relation_tag alias for $3; -- default ''generic'' - register_child_type__min_n alias for $4; -- default 0 - register_child_type__max_n alias for $5; -- default null + +-- old define_function_args('content_type__register_child_type','parent_type,child_type,relation_tag;generic,min_n;0,max_n') +-- new +select define_function_args('content_type__register_child_type','parent_type,child_type,relation_tag;generic,min_n;0,max_n;null'); + + + +-- +-- procedure content_type__register_child_type/5 +-- +CREATE OR REPLACE FUNCTION content_type__register_child_type( + register_child_type__parent_type varchar, + register_child_type__child_type varchar, + register_child_type__relation_tag varchar, -- default 'generic' + register_child_type__min_n integer, -- default 0 -- default '0' + register_child_type__max_n integer -- default null + +) RETURNS integer AS $$ +DECLARE v_exists integer; -begin +BEGIN select count(*) into v_exists from cr_type_children @@ -888,19 +984,29 @@ end if; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -select define_function_args('content_type__unregister_child_type','content_type,child_type,relation_tag'); -create or replace function content_type__unregister_child_type (varchar,varchar,varchar) -returns integer as ' -declare - unregister_child_type__parent_type alias for $1; - unregister_child_type__child_type alias for $2; - unregister_child_type__relation_tag alias for $3; -begin +-- old define_function_args('content_type__unregister_child_type','content_type,child_type,relation_tag') +-- new +select define_function_args('content_type__unregister_child_type','parent_type,child_type,relation_tag'); + + + +-- +-- procedure content_type__unregister_child_type/3 +-- +CREATE OR REPLACE FUNCTION content_type__unregister_child_type( + unregister_child_type__parent_type varchar, + unregister_child_type__child_type varchar, + unregister_child_type__relation_tag varchar +) RETURNS integer AS $$ +DECLARE +BEGIN + delete from cr_type_children where @@ -911,21 +1017,32 @@ relation_tag = unregister_child_type__relation_tag; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -select define_function_args('content_type__register_relation_type','content_type,target_type,relation_tag;generic,min_n;0,max_n'); -create or replace function content_type__register_relation_type (varchar,varchar,varchar,integer,integer) -returns integer as ' -declare - register_relation_type__content_type alias for $1; - register_relation_type__target_type alias for $2; - register_relation_type__relation_tag alias for $3; -- default ''generic'' - register_relation_type__min_n alias for $4; -- default 0 - register_relation_type__max_n alias for $5; -- default null +-- old define_function_args('content_type__register_relation_type','content_type,target_type,relation_tag;generic,min_n;0,max_n') +-- new +select define_function_args('content_type__register_relation_type','content_type,target_type,relation_tag;generic,min_n;0,max_n;null'); + + + + +-- +-- procedure content_type__register_relation_type/5 +-- +CREATE OR REPLACE FUNCTION content_type__register_relation_type( + register_relation_type__content_type varchar, + register_relation_type__target_type varchar, + register_relation_type__relation_tag varchar, -- default 'generic' + register_relation_type__min_n integer, -- default 0 -- default '0' + register_relation_type__max_n integer -- default null + +) RETURNS integer AS $$ +DECLARE v_exists integer; -begin +BEGIN -- check if the relation type exists select @@ -964,19 +1081,26 @@ end if; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select define_function_args('content_type__unregister_relation_type','content_type,target_type,relation_tag;null'); -create or replace function content_type__unregister_relation_type (varchar,varchar,varchar) -returns integer as ' -declare - unregister_relation_type__content_type alias for $1; - unregister_relation_type__target_type alias for $2; - unregister_relation_type__relation_tag alias for $3; -- default null + + +-- +-- procedure content_type__unregister_relation_type/3 +-- +CREATE OR REPLACE FUNCTION content_type__unregister_relation_type( + unregister_relation_type__content_type varchar, + unregister_relation_type__target_type varchar, + unregister_relation_type__relation_tag varchar -- default null + +) RETURNS integer AS $$ +DECLARE -begin +BEGIN delete from cr_type_relations @@ -988,18 +1112,24 @@ relation_tag = unregister_relation_type__relation_tag; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select define_function_args('content_type__register_mime_type','content_type,mime_type'); -create or replace function content_type__register_mime_type (varchar,varchar) -returns integer as ' -declare - register_mime_type__content_type alias for $1; - register_mime_type__mime_type alias for $2; + + +-- +-- procedure content_type__register_mime_type/2 +-- +CREATE OR REPLACE FUNCTION content_type__register_mime_type( + register_mime_type__content_type varchar, + register_mime_type__mime_type varchar +) RETURNS integer AS $$ +DECLARE v_valid_registration integer; -begin +BEGIN -- check if this type is already registered select @@ -1026,62 +1156,80 @@ end if; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select define_function_args('content_type__unregister_mime_type','content_type,mime_type'); -create or replace function content_type__unregister_mime_type (varchar,varchar) -returns integer as ' -declare - unregister_mime_type__content_type alias for $1; - unregister_mime_type__mime_type alias for $2; -begin + +-- +-- procedure content_type__unregister_mime_type/2 +-- +CREATE OR REPLACE FUNCTION content_type__unregister_mime_type( + unregister_mime_type__content_type varchar, + unregister_mime_type__mime_type varchar +) RETURNS integer AS $$ +DECLARE +BEGIN + delete from cr_content_mime_type_map where content_type = unregister_mime_type__content_type and mime_type = unregister_mime_type__mime_type; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select define_function_args('content_type__is_content_type','object_type'); -create or replace function content_type__is_content_type (varchar) -returns boolean as ' -declare - is_content_type__object_type alias for $1; + + +-- +-- procedure content_type__is_content_type/1 +-- +CREATE OR REPLACE FUNCTION content_type__is_content_type( + is_content_type__object_type varchar +) RETURNS boolean AS $$ +DECLARE v_is_content_type boolean; -begin +BEGIN - if is_content_type__object_type = ''content_revision'' then + if is_content_type__object_type = 'content_revision' then - v_is_content_type := ''t''; + v_is_content_type := 't'; else select count(*) > 0 into v_is_content_type from acs_object_type_supertype_map where object_type = is_content_type__object_type - and ancestor_type = ''content_revision''; + and ancestor_type = 'content_revision'; end if; return v_is_content_type; -end;' language 'plpgsql' stable; +END; +$$ LANGUAGE plpgsql stable; select define_function_args('content_type__rotate_template','template_id,v_content_type,use_context'); -create or replace function content_type__rotate_template (integer,varchar,varchar) -returns integer as ' -declare - rotate_template__template_id alias for $1; - rotate_template__v_content_type alias for $2; - rotate_template__use_context alias for $3; + + +-- +-- procedure content_type__rotate_template/3 +-- +CREATE OR REPLACE FUNCTION content_type__rotate_template( + rotate_template__template_id integer, + rotate_template__v_content_type varchar, + rotate_template__use_context varchar +) RETURNS integer AS $$ +DECLARE v_template_id cr_templates.template_id%TYPE; v_items_val record; -begin +BEGIN -- get the default template select @@ -1093,7 +1241,7 @@ and use_context = rotate_template__use_context and - is_default = ''t''; + is_default = 't'; if v_template_id is not null then @@ -1131,12 +1279,13 @@ rotate_template__v_content_type, rotate_template__template_id, rotate_template__use_context, - ''t'' + 't' ); end if; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; @@ -1146,23 +1295,30 @@ -- prompt *** Refreshing content type attribute views... -create or replace function inline_0 () -returns integer as ' -declare + + +-- +-- procedure inline_0/0 +-- +CREATE OR REPLACE FUNCTION inline_0( + +) RETURNS integer AS $$ +DECLARE type_rec record; -begin +BEGIN for type_rec in select ot.object_type from acs_object_types ot, acs_object_types ot2 - where ot2.object_type = ''content_revision'' + where ot2.object_type = 'content_revision' and ot.tree_sortkey between ot2.tree_sortkey and tree_right(ot2.tree_sortkey) order by ot.tree_sortkey LOOP PERFORM content_type__refresh_view (type_rec.object_type); end LOOP; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select inline_0 (); Index: openacs-4/packages/acs-content-repository/sql/postgresql/content-update.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/sql/postgresql/content-update.sql,v diff -u -r1.8 -r1.9 --- openacs-4/packages/acs-content-repository/sql/postgresql/content-update.sql 4 Jun 2006 00:45:23 -0000 1.8 +++ openacs-4/packages/acs-content-repository/sql/postgresql/content-update.sql 7 Jul 2011 10:46:02 -0000 1.9 @@ -14,197 +14,198 @@ --set serveroutput on -- FIXME: drop constraint doesn't work on postgresql -create function inline_0 () -returns integer as ' -begin +CREATE OR REPLACE FUNCTION inline_0 () RETURNS integer AS $$ +BEGIN -- altering the constraint on cr_type_template_map - raise NOTICE ''Altering constraint on cr_type_template_map...''; - execute ''alter table cr_type_template_map drop constraint cr_type_template_map_pk''; - execute ''alter table cr_type_template_map add constraint cr_type_template_map_pk primary key (content_type, template_id, use_context)''; - execute ''VACUUM ANALYZE cr_type_template_map''; + raise NOTICE 'Altering constraint on cr_type_template_map...'; + execute 'alter table cr_type_template_map drop constraint cr_type_template_map_pk'; + execute 'alter table cr_type_template_map add constraint cr_type_template_map_pk primary key (content_type, template_id, use_context)'; + execute 'VACUUM ANALYZE cr_type_template_map'; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- select inline_0 (); drop function inline_0 (); -create function inline_1 () returns integer as ' -begin +CREATE OR REPLACE FUNCTION inline_1 () RETURNS integer AS $$ +BEGIN -- Set the workflow permission as child of admin update acs_privilege_hierarchy - set privilege = ''cm_admin'' + set privilege = 'cm_admin' where - privilege = ''cm_write'' + privilege = 'cm_write' and - child_privilege = ''cm_item_workflow''; + child_privilege = 'cm_item_workflow'; - if not table_exists(''cr_doc_filter'') then + if not table_exists('cr_doc_filter') then - raise NOTICE ''Creating CR_DOC_FILTER table for converting - documents to HTML''; + raise NOTICE 'Creating CR_DOC_FILTER table for converting + documents to HTML'; - execute ''create table cr_doc_filter ( + execute 'create table cr_doc_filter ( revision_id integer primary key, content integer - )''; + )'; - -- execute ''create index cr_doc_filter_index + -- execute 'create index cr_doc_filter_index -- on cr_doc_filter ( content ) indextype is ctxsys.context - -- parameters (''''FILTER content_filter_pref'''' )''; + -- parameters (''FILTER content_filter_pref'' )'; end if; - if not table_exists(''cr_content_text'') then + if not table_exists('cr_content_text') then - raise NOTICE ''Creating CR_CONTENT_TEXT table''; + raise NOTICE 'Creating CR_CONTENT_TEXT table'; - execute ''create table cr_content_text ( + execute 'create table cr_content_text ( revision_id integer primary key, content text - )''; + )'; end if; - if not column_exists(''cr_folders'', ''has_child_folders'') then + if not column_exists('cr_folders', 'has_child_folders') then - raise NOTICE ''Adding HAS_CHILD_FOLDERS column to CR_FOLDERS and updating the column based on selection criteria.''; + raise NOTICE 'Adding HAS_CHILD_FOLDERS column to CR_FOLDERS and updating the column based on selection criteria.'; - execute ''create view cr_resolved_items as + execute 'create view cr_resolved_items as select i.parent_id, i.item_id, i.name, - case s.target_id is NULL then \\\'\\\'f\\\'\\\' else \\\'\\\'t\\\'\\\' end as is_symlink, + case s.target_id is NULL then ''''f'''' else ''''t'''' end as is_symlink, coalesce(s.target_id, i.item_id) resolved_id, s.label from cr_items i left outer join cr_symlinks s - on i.item_id = s.symlink_id''; + on i.item_id = s.symlink_id'; - execute ''alter table cr_folders add + execute 'alter table cr_folders add has_child_folders boolean - default \\\'\\\'f\\\'\\\'''; + default ''''f'''''; - execute ''update cr_folders f set has_child_folders = - coalesce((select \\\'\\\'t\\\'\\\' from dual where exists + execute 'update cr_folders f set has_child_folders = + coalesce((select ''''t'''' from dual where exists (select 1 from cr_folders f_child, cr_resolved_items r_child where r_child.parent_id = f.folder_id - and f_child.folder_id = r_child.resolved_id)), \\\'\\\'f\\\'\\\')''; + and f_child.folder_id = r_child.resolved_id)), ''''f'''')'; end if; - if not column_exists(''cr_keywords'', ''parent_id'') then + if not column_exists('cr_keywords', 'parent_id') then - raise NOTICE ''Adding PARENT_ID column to CR_KEYWORDS and updating the parent id from the context id''; + raise NOTICE 'Adding PARENT_ID column to CR_KEYWORDS and updating the parent id from the context id'; - execute ''alter table cr_keywords add + execute 'alter table cr_keywords add parent_id integer constraint cr_keywords_hier - references cr_keywords''; + references cr_keywords'; - execute ''update cr_keywords set parent_id = ( + execute 'update cr_keywords set parent_id = ( select context_id from acs_objects - where object_id = keyword_id)''; + where object_id = keyword_id)'; end if; - if not table_exists(''cr_text'') then + if not table_exists('cr_text') then - raise NOTICE ''Creating CR_TEXT table for incoming text submissions...''; + raise NOTICE 'Creating CR_TEXT table for incoming text submissions...'; - execute ''create table cr_text ( text text default \\\'\\\' not null )''; + execute 'create table cr_text ( text text default '''' not null )'; -- For some reason a simple insert statement throws an error but this works - execute ''insert into cr_text values (NULL)''; + execute 'insert into cr_text values (NULL)'; end if; - if not column_exists(''cr_items'', ''publish_status'') then + if not column_exists('cr_items', 'publish_status') then - raise NOTICE ''Adding PUBLISH_STATUS column to CR_ITEMS for tracking deployment status...''; + raise NOTICE 'Adding PUBLISH_STATUS column to CR_ITEMS for tracking deployment status...'; - execute ''alter table cr_items add + execute 'alter table cr_items add publish_status varchar(40) constraint cr_items_pub_status_chk check (publish_status in - (\\\'\\\'production\\\'\\\', \\\'\\\'ready\\\'\\\', \\\'\\\'live\\\'\\\', \\\'\\\'expired\\\'\\\'))''; + (''''production'''', ''''ready'''', ''''live'''', ''''expired''''))'; - execute ''update cr_items set publish_status = \\\'\\\'live\\\'\\\' - where live_revision is not null''; + execute 'update cr_items set publish_status = ''''live'''' + where live_revision is not null'; - execute ''alter table cr_item_publish_audit add column - old_status varchar(40)''; - execute ''alter table cr_item_publish_audit add column - new_status varchar(40)''; + execute 'alter table cr_item_publish_audit add column + old_status varchar(40)'; + execute 'alter table cr_item_publish_audit add column + new_status varchar(40)'; end if; - if not column_exists(''cr_items'', ''latest_revision'') then + if not column_exists('cr_items', 'latest_revision') then - raise NOTICE ''Adding LATEST_REVISION column to CR_ITEMS for tracking revision status...''; + raise NOTICE 'Adding LATEST_REVISION column to CR_ITEMS for tracking revision status...'; - execute ''alter table cr_items add + execute 'alter table cr_items add latest_revision integer constraint cr_items_latest_fk - references cr_revisions''; + references cr_revisions'; - execute ''update cr_items + execute 'update cr_items set latest_revision = - content_item__get_latest_revision(item_id)''; + content_item__get_latest_revision(item_id)'; end if; - if not table_exists(''cr_release_periods'') then + if not table_exists('cr_release_periods') then - raise NOTICE ''Creating CR_RELEASE_PERIODS table for scheduled publishing...''; + raise NOTICE 'Creating CR_RELEASE_PERIODS table for scheduled publishing...'; - execute '' + execute ' create table cr_release_periods ( item_id integer constraint cr_release_periods_fk references cr_items constraint cr_release_periods_pk primary key, start_when timestamptz default current_timestamp, - end_when timestamptz default current_timestamp + interval ''''20 years'''' - )''; + end_when timestamptz default current_timestamp + interval ''20 years'' + )'; end if; - if not table_exists(''cr_scheduled_release_log'') then + if not table_exists('cr_scheduled_release_log') then - raise NOTICE ''Creating CR_SCHEDULED_RELEASE_LOG table for auditing of scheduled publishing...''; + raise NOTICE 'Creating CR_SCHEDULED_RELEASE_LOG table for auditing of scheduled publishing...'; - execute '' + execute ' create table cr_scheduled_release_log ( exec_date timestamptz default current_timestamp not null, items_released integer not null, items_expired integer not null, err_num integer, - err_msg varchar(500) default \\\'\\\' not null - )''; + err_msg varchar(500) default '''' not null + )'; end if; - if not table_exists(''cr_scheduled_release_job'') then + if not table_exists('cr_scheduled_release_job') then - raise NOTICE ''Creating CR_SCHEDULED_RELEASE_JOB table for tracking database job for scheduled publishing...''; + raise NOTICE 'Creating CR_SCHEDULED_RELEASE_JOB table for tracking database job for scheduled publishing...'; - execute '' + execute ' create table cr_scheduled_release_job ( job_id integer, last_exec timestamptz - )''; + )'; - execute '' - insert into cr_scheduled_release_job values (NULL, now())''; + execute ' + insert into cr_scheduled_release_job values (NULL, now())'; end if; return null; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- select inline_1 (); Index: openacs-4/packages/acs-content-repository/sql/postgresql/content-util.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/sql/postgresql/content-util.sql,v diff -u -r1.8 -r1.9 --- openacs-4/packages/acs-content-repository/sql/postgresql/content-util.sql 17 Sep 2007 12:58:30 -0000 1.8 +++ openacs-4/packages/acs-content-repository/sql/postgresql/content-util.sql 7 Jul 2011 10:46:02 -0000 1.9 @@ -10,66 +10,114 @@ -- License. Full text of the license is available from the GNU Project: -- http://www.fsf.org/copyleft/gpl.html -create function table_exists (varchar) -returns boolean as ' -declare - table_exists__table_name alias for $1; -begin + +-- added +select define_function_args('table_exists','table_name'); + +-- +-- procedure table_exists/1 +-- +CREATE OR REPLACE FUNCTION table_exists( + table_exists__table_name varchar +) RETURNS boolean AS $$ +DECLARE +BEGIN + return count(*) > 0 from pg_class where relname = lower(table_exists__table_name); -end;' language 'plpgsql' stable strict; +END; +$$ LANGUAGE plpgsql stable strict; -create or replace function column_exists (varchar,varchar) -returns boolean as ' -declare - column_exists__table_name alias for $1; - column_exists__column_name alias for $2; -begin + +-- added +select define_function_args('column_exists','table_name,column_name'); + +-- +-- procedure column_exists/2 +-- +CREATE OR REPLACE FUNCTION column_exists( + column_exists__table_name varchar, + column_exists__column_name varchar +) RETURNS boolean AS $$ +DECLARE +BEGIN + return count(*) > 0 from pg_class c, pg_attribute a where c.relname = lower(column_exists__table_name) and c.oid = a.attrelid and a.attname = lower(column_exists__column_name); -end;' language 'plpgsql' stable; +END; +$$ LANGUAGE plpgsql stable; -create or replace function trigger_exists (varchar,varchar) returns boolean as ' -declare - trigger_name alias for $1; - on_table alias for $2; -begin + + +-- added +select define_function_args('trigger_exists','trigger_name,on_table'); + +-- +-- procedure trigger_exists/2 +-- +CREATE OR REPLACE FUNCTION trigger_exists( + trigger_name varchar, + on_table varchar +) RETURNS boolean AS $$ +DECLARE +BEGIN return count(*) > 0 from pg_class c, pg_trigger t where c.relname = lower(on_table) and c.oid = t.tgrelid and t.tgname = lower(trigger_name); -end;' language 'plpgsql' stable; +END; +$$ LANGUAGE plpgsql stable; -create or replace function trigger_func_exists (varchar) returns boolean as ' -declare - trigger_name alias for $1; -begin + + +-- added +select define_function_args('trigger_func_exists','trigger_name'); + +-- +-- procedure trigger_func_exists/1 +-- +CREATE OR REPLACE FUNCTION trigger_func_exists( + trigger_name varchar +) RETURNS boolean AS $$ +DECLARE +BEGIN return count(*) = 1 from pg_proc where proname = lower(trigger_name) and pronargs = 0; -end;' language 'plpgsql' stable; +END; +$$ LANGUAGE plpgsql stable; -create or replace function rule_exists (varchar,varchar) returns boolean as ' -declare - rule_name alias for $1; - table_name alias for $2; -begin + + +-- added +select define_function_args('rule_exists','rule_name,table_name'); + +-- +-- procedure rule_exists/2 +-- +CREATE OR REPLACE FUNCTION rule_exists( + rule_name varchar, + table_name varchar +) RETURNS boolean AS $$ +DECLARE +BEGIN return count(*) = 1 from pg_rules where tablename::varchar = lower(table_name) and rulename::varchar = lower(rule_name); -end;' language 'plpgsql' stable; +END; +$$ LANGUAGE plpgsql stable; Index: openacs-4/packages/acs-content-repository/sql/postgresql/doc-package.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/sql/postgresql/doc-package.sql,v diff -u -r1.5 -r1.6 --- openacs-4/packages/acs-content-repository/sql/postgresql/doc-package.sql 11 Dec 2003 21:39:47 -0000 1.5 +++ openacs-4/packages/acs-content-repository/sql/postgresql/doc-package.sql 7 Jul 2011 10:46:02 -0000 1.6 @@ -4,28 +4,46 @@ -- show errors -create or replace function doc__get_proc_header (varchar,varchar) -returns varchar as ' -declare - proc_name alias for $1; - package_name alias for $2; -begin + + +-- added +select define_function_args('doc__get_proc_header','proc_name,package_name'); + +-- +-- procedure doc__get_proc_header/2 +-- +CREATE OR REPLACE FUNCTION doc__get_proc_header( + proc_name varchar, + package_name varchar +) RETURNS varchar AS $$ +DECLARE +BEGIN return definition from acs_func_headers - where fname = (package_name || ''__'' || proc_name)::name + where fname = (package_name || '__' || proc_name)::name limit 1; -end;' language 'plpgsql' stable; +END; +$$ LANGUAGE plpgsql stable; -create or replace function doc__get_package_header (varchar) -returns varchar as ' -declare - package_name alias for $1; -begin - return ''''; -end;' language 'plpgsql' immutable strict; +-- added +select define_function_args('doc__get_package_header','package_name'); +-- +-- procedure doc__get_package_header/1 +-- +CREATE OR REPLACE FUNCTION doc__get_package_header( + package_name varchar +) RETURNS varchar AS $$ +DECLARE +BEGIN + + return ''; + +END; +$$ LANGUAGE plpgsql immutable strict; + -- show errors Index: openacs-4/packages/acs-content-repository/sql/postgresql/types-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/sql/postgresql/types-create.sql,v diff -u -r1.7 -r1.8 --- openacs-4/packages/acs-content-repository/sql/postgresql/types-create.sql 11 Apr 2011 00:28:54 -0000 1.7 +++ openacs-4/packages/acs-content-repository/sql/postgresql/types-create.sql 7 Jul 2011 10:46:02 -0000 1.8 @@ -564,26 +564,34 @@ -- prompt *** Refreshing content type attribute views... -create function inline_0 () returns integer as ' -declare + + +-- +-- procedure inline_0/0 +-- +CREATE OR REPLACE FUNCTION inline_0( + +) RETURNS integer AS $$ +DECLARE type_rec record; -begin +BEGIN -- select object_type from acs_object_types -- connect by supertype = prior object_type --- start with object_type = ''content_revision'' +-- start with object_type = 'content_revision' for type_rec in select o1.object_type from acs_object_types o1, acs_object_types o2 where o1.tree_sortkey between o2.tree_sortkey and tree_right(o2.tree_sortkey) - and o2.object_type = ''content_revision'' + and o2.object_type = 'content_revision' LOOP PERFORM content_type__refresh_view(type_rec.object_type); end LOOP; return null; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select inline_0(); Index: openacs-4/packages/acs-kernel/sql/postgresql/acs-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/postgresql/acs-create.sql,v diff -u -r1.37 -r1.38 --- openacs-4/packages/acs-kernel/sql/postgresql/acs-create.sql 27 Oct 2007 22:10:59 -0000 1.37 +++ openacs-4/packages/acs-kernel/sql/postgresql/acs-create.sql 7 Jul 2011 10:46:01 -0000 1.38 @@ -18,45 +18,37 @@ objects like the site-wide organization, and the all users party. '; -create or replace function acs__add_user ( - integer, -- user_id - varchar, -- object_type - timestamptz, -- creation_date - integer, -- creation_user - varchar, -- cretion_ip - integer, -- authority_id; default 'local' - varchar, -- username - varchar, -- email - varchar, -- url - varchar, -- first_names - varchar, -- last_name - char, -- password - char, -- salt - varchar, -- screen_name - boolean, -- email_verified_p - varchar -- member_state -) -returns integer as ' -declare - p_user_id alias for $1; -- default null - p_object_type alias for $2; -- default ''user'' - p_creation_date alias for $3; -- default now() - p_creation_user alias for $4; -- default null - p_creation_ip alias for $5; -- default null - p_authority_id alias for $6; -- defaults to local authority - p_username alias for $7; -- - p_email alias for $8; - p_url alias for $9; -- default null - p_first_names alias for $10; - p_last_name alias for $11; - p_password alias for $12; - p_salt alias for $13; - p_screen_name alias for $14; -- default null - p_email_verified_p alias for $15; -- default ''t'' - p_member_state alias for $16; -- default ''approved'' + + +-- added +select define_function_args('acs__add_user','user_id;null,object_type;user,creation_date;now(),creation_user;null,creation_ip;null,authority_id,username,email,url;null,first_names,last_name,password,salt,screen_name;null,email_verified_p;t,member_state;approved'); + +-- +-- procedure acs__add_user/16 +-- +CREATE OR REPLACE FUNCTION acs__add_user( + p_user_id integer, -- default null + p_object_type varchar, -- default 'user' + p_creation_date timestamptz, -- default now() + p_creation_user integer, -- default null + p_creation_ip varchar, -- default null + p_authority_id integer, -- defaults to local authority + p_username varchar, + p_email varchar, + p_url varchar, -- default null + p_first_names varchar, + p_last_name varchar, + p_password char, + p_salt char, + p_screen_name varchar, -- default null + p_email_verified_p boolean, -- default 't' + p_member_state varchar -- default 'approved' + +) RETURNS integer AS $$ +DECLARE v_user_id users.user_id%TYPE; v_rel_id membership_rels.rel_id%TYPE; -begin +BEGIN v_user_id := acs_user__new ( p_user_id, p_object_type, @@ -78,8 +70,8 @@ v_rel_id := membership_rel__new ( null, - ''membership_rel'', - acs__magic_object_id(''registered_users''), + 'membership_rel', + acs__magic_object_id('registered_users'), v_user_id, p_member_state, null, @@ -88,25 +80,34 @@ PERFORM acs_permission__grant_permission ( v_user_id, v_user_id, - ''read'' + 'read' ); PERFORM acs_permission__grant_permission ( v_user_id, v_user_id, - ''write'' + 'write' ); return v_user_id; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create function acs__remove_user (integer) -returns integer as ' -declare - remove_user__user_id alias for $1; + + +-- added +select define_function_args('acs__remove_user','user_id'); + +-- +-- procedure acs__remove_user/1 +-- +CREATE OR REPLACE FUNCTION acs__remove_user( + remove_user__user_id integer +) RETURNS integer AS $$ +DECLARE v_rec record; -begin +BEGIN delete from acs_permissions where grantee_id = remove_user__user_id; @@ -121,17 +122,27 @@ perform acs_user__delete(remove_user__user_id); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create function acs__magic_object_id (varchar) -returns integer as ' -declare - magic_object_id__name alias for $1; -begin + + +-- added +select define_function_args('acs__magic_object_id','name'); + +-- +-- procedure acs__magic_object_id/1 +-- +CREATE OR REPLACE FUNCTION acs__magic_object_id( + magic_object_id__name varchar +) RETURNS integer AS $$ +DECLARE +BEGIN return object_id from acs_magic_objects where name = magic_object_id__name; -end;' language 'plpgsql' stable strict; +END; +$$ LANGUAGE plpgsql stable strict; -- ****************************************************************** -- * Community Core API @@ -182,33 +193,40 @@ -- The very first thing we must do is create the security_context_root -- object. -create function inline_0 () -returns integer as ' -declare + + +-- +-- procedure inline_0/0 +-- +CREATE OR REPLACE FUNCTION inline_0( + +) RETURNS integer AS $$ +DECLARE root_id integer; -begin +BEGIN root_id := acs_object__new ( -4, - ''acs_object'', + 'acs_object', now(), null, null, null, - ''t'', - ''#acs-kernel.lt_Security_context_root#'', + 't', + '#acs-kernel.lt_Security_context_root#', null ); insert into acs_magic_objects (name, object_id) values - (''security_context_root'', -4); + ('security_context_root', -4); return root_id; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select inline_0 (); @@ -245,19 +263,25 @@ -- Now create our special groups and users. We can not create the -- relationships between these entities yet. This is done in acs-install.sql -create function inline_2 () -returns integer as ' -declare + + +-- +-- procedure inline_2/0 +-- +CREATE OR REPLACE FUNCTION inline_2( + +) RETURNS integer AS $$ +DECLARE v_object_id integer; -begin +BEGIN -- Make an "Unregistered Visitor" as object 0, which corresponds -- with the user_id assigned throughout the toolkit Tcl code insert into acs_objects (object_id, object_type, title) values - (0, ''user'', ''#acs-kernel.Unregistered_Visitor#''); + (0, 'user', '#acs-kernel.Unregistered_Visitor#'); insert into parties (party_id) @@ -267,96 +291,104 @@ insert into persons (person_id, first_names, last_name) values - (0, ''#acs-kernel.Unregistered#'', ''#acs-kernel.Visitor#''); + (0, '#acs-kernel.Unregistered#', '#acs-kernel.Visitor#'); insert into users (user_id, username) values - (0, ''guest''); + (0, 'guest'); insert into acs_magic_objects (name, object_id) values - (''unregistered_visitor'', 0); + ('unregistered_visitor', 0); v_object_id := acs_group__new ( -1, - ''group'', + 'group', now(), null, null, null, null, - ''#acs-kernel.The_Public#'', - ''closed'', + '#acs-kernel.The_Public#', + 'closed', null ); insert into acs_magic_objects (name, object_id) values - (''the_public'', -1); + ('the_public', -1); -- Add our only user, the Unregistered Visitor, to The Public -- group. perform membership_rel__new ( null, - ''membership_rel'', - acs__magic_object_id(''the_public''), - acs__magic_object_id(''unregistered_visitor''), - ''approved'', + 'membership_rel', + acs__magic_object_id('the_public'), + acs__magic_object_id('unregistered_visitor'), + 'approved', null, null); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select inline_2 (); drop function inline_2 (); -create function inline_3 () -returns integer as ' -declare + + +-- +-- procedure inline_3/0 +-- +CREATE OR REPLACE FUNCTION inline_3( + +) RETURNS integer AS $$ +DECLARE group_id integer; -begin +BEGIN -- We will create the registered users group with type group for the moment -- because the application_group package has not yet been created. group_id := acs_group__new ( -2, - ''group'', + 'group', now(), null, null, null, null, - ''#acs-kernel.Registered_Users#'', - ''closed'', + '#acs-kernel.Registered_Users#', + 'closed', null ); insert into acs_magic_objects (name, object_id) values - (''registered_users'', -2); + ('registered_users', -2); -- Now declare "The Public" to be composed of itself and the "Registered -- Users" group perform composition_rel__new ( null, - ''composition_rel'', - acs__magic_object_id(''the_public''), - acs__magic_object_id(''registered_users''), + 'composition_rel', + acs__magic_object_id('the_public'), + acs__magic_object_id('registered_users'), null, null); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select inline_3 (); Index: openacs-4/packages/acs-kernel/sql/postgresql/acs-install.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/postgresql/acs-install.sql,v diff -u -r1.27 -r1.28 --- openacs-4/packages/acs-kernel/sql/postgresql/acs-install.sql 4 Jun 2006 00:45:38 -0000 1.27 +++ openacs-4/packages/acs-kernel/sql/postgresql/acs-install.sql 7 Jul 2011 10:46:01 -0000 1.28 @@ -8,22 +8,28 @@ -- @cvs-id $Id$ -- -create function inline_0 () -returns integer as ' -declare + + +-- +-- procedure inline_0/0 +-- +CREATE OR REPLACE FUNCTION inline_0( + +) RETURNS integer AS $$ +DECLARE node_id site_nodes.node_id%TYPE; main_site_id site_nodes.node_id%TYPE; -begin +BEGIN main_site_id := apm_service__new( null, - ''#acs-kernel.Main_Site#'', - ''acs-subsite'', - ''apm_service'', + '#acs-kernel.Main_Site#', + 'acs-subsite', + 'apm_service', now(), null, null, - acs__magic_object_id(''default_context'') + acs__magic_object_id('default_context') ); @@ -35,65 +41,66 @@ (-2, main_site_id); update acs_objects - set object_type = ''application_group'', + set object_type = 'application_group', context_id = main_site_id where object_id = -2; insert into group_rels (group_rel_id, group_id, rel_type) - select nextval(''t_acs_object_id_seq''), -2, ''admin_rel''; + select nextval('t_acs_object_id_seq'), -2, 'admin_rel'; -- Create the members and admins rel segments perform rel_segment__new( null, - ''rel_segment'', + 'rel_segment', now(), null, null, null, null, - ''#acs-kernel.Main_Site_Members#'', + '#acs-kernel.Main_Site_Members#', -2, - ''membership_rel'', + 'membership_rel', null ); perform rel_segment__new( null, - ''rel_segment'', + 'rel_segment', now(), null, null, null, null, - ''#acs-kernel.lt_Main_Site_Administrat#'', + '#acs-kernel.lt_Main_Site_Administrat#', -2, - ''admin_rel'', + 'admin_rel', null ); node_id := site_node__new ( null, null, - '''', + '', main_site_id, - ''t'', - ''t'', + 't', + 't', null, null ); perform acs_permission__grant_permission ( main_site_id, - acs__magic_object_id(''the_public''), - ''read'' + acs__magic_object_id('the_public'), + 'read' ); return null; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select inline_0 (); Index: openacs-4/packages/acs-kernel/sql/postgresql/acs-logs-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/postgresql/acs-logs-create.sql,v diff -u -r1.7 -r1.8 --- openacs-4/packages/acs-kernel/sql/postgresql/acs-logs-create.sql 10 Feb 2009 18:31:54 -0000 1.7 +++ openacs-4/packages/acs-kernel/sql/postgresql/acs-logs-create.sql 7 Jul 2011 10:46:02 -0000 1.8 @@ -52,67 +52,103 @@ -- create or replace package body acs_log -- procedure notice -create function acs_log__notice (varchar,varchar) -returns integer as ' -declare - notice__log_key alias for $1; - notice__message alias for $2; -begin + + +-- added +select define_function_args('acs_log__notice','log_key,message'); + +-- +-- procedure acs_log__notice/2 +-- +CREATE OR REPLACE FUNCTION acs_log__notice( + notice__log_key varchar, + notice__message varchar +) RETURNS integer AS $$ +DECLARE +BEGIN insert into acs_logs (log_id, log_level, log_key, message) values - (nextval(''t_acs_log_id_seq''), ''notice'', notice__log_key, notice__message); + (nextval('t_acs_log_id_seq'), 'notice', notice__log_key, notice__message); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure warn -create function acs_log__warn (varchar,varchar) -returns integer as ' -declare - warn__log_key alias for $1; - warn__message alias for $2; -begin + + +-- added +select define_function_args('acs_log__warn','log_key,message'); + +-- +-- procedure acs_log__warn/2 +-- +CREATE OR REPLACE FUNCTION acs_log__warn( + warn__log_key varchar, + warn__message varchar +) RETURNS integer AS $$ +DECLARE +BEGIN insert into acs_logs (log_id, log_level, log_key, message) values - (nextval(''t_acs_log_id_seq''), ''warn'', warn__log_key, warn__message); + (nextval('t_acs_log_id_seq'), 'warn', warn__log_key, warn__message); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure error -create function acs_log__error (varchar,varchar) -returns integer as ' -declare - error__log_key alias for $1; - error__message alias for $2; -begin + + +-- added +select define_function_args('acs_log__error','log_key,message'); + +-- +-- procedure acs_log__error/2 +-- +CREATE OR REPLACE FUNCTION acs_log__error( + error__log_key varchar, + error__message varchar +) RETURNS integer AS $$ +DECLARE +BEGIN insert into acs_logs (log_id, log_level, log_key, message) values - (nextval(''t_acs_log_id_seq''), ''error'', error__log_key, error__message); + (nextval('t_acs_log_id_seq'), 'error', error__log_key, error__message); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure debug -create function acs_log__debug (varchar,varchar) -returns integer as ' -declare - debug__log_key alias for $1; - debug__message alias for $2; -begin + + +-- added +select define_function_args('acs_log__debug','log_key,message'); + +-- +-- procedure acs_log__debug/2 +-- +CREATE OR REPLACE FUNCTION acs_log__debug( + debug__log_key varchar, + debug__message varchar +) RETURNS integer AS $$ +DECLARE +BEGIN insert into acs_logs (log_id, log_level, log_key, message) values - (nextval(''t_acs_log_id_seq''), ''debug'', debug__log_key, debug__message); + (nextval('t_acs_log_id_seq'), 'debug', debug__log_key, debug__message); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; Index: openacs-4/packages/acs-kernel/sql/postgresql/acs-metadata-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/postgresql/acs-metadata-create.sql,v diff -u -r1.39 -r1.40 --- openacs-4/packages/acs-kernel/sql/postgresql/acs-metadata-create.sql 26 May 2011 04:07:37 -0000 1.39 +++ openacs-4/packages/acs-kernel/sql/postgresql/acs-metadata-create.sql 7 Jul 2011 10:46:02 -0000 1.40 @@ -54,18 +54,35 @@ -- support for tree queries on acs_object_types -create or replace function acs_object_type_get_tree_sortkey(varchar) returns varbit as ' -declare - p_object_type alias for $1; -begin + + +-- added +select define_function_args('acs_object_type_get_tree_sortkey','object_type'); + +-- +-- procedure acs_object_type_get_tree_sortkey/1 +-- +CREATE OR REPLACE FUNCTION acs_object_type_get_tree_sortkey( + p_object_type varchar +) RETURNS varbit AS $$ +DECLARE +BEGIN return tree_sortkey from acs_object_types where object_type = p_object_type; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create function acs_object_type_insert_tr () returns trigger as ' -declare + + +-- +-- procedure acs_object_type_insert_tr/0 +-- +CREATE OR REPLACE FUNCTION acs_object_type_insert_tr( + +) RETURNS trigger AS $$ +DECLARE v_parent_sk varbit default null; v_max_value integer; -begin +BEGIN select max(tree_leaf_key_to_int(tree_sortkey)) into v_max_value from acs_object_types where supertype = new.supertype; @@ -78,19 +95,27 @@ return new; -end;' language 'plpgsql' stable strict; +END; +$$ LANGUAGE plpgsql stable strict; create trigger acs_object_type_insert_tr before insert on acs_object_types for each row execute procedure acs_object_type_insert_tr (); -create function acs_object_type_update_tr () returns trigger as ' -declare + + +-- +-- procedure acs_object_type_update_tr/0 +-- +CREATE OR REPLACE FUNCTION acs_object_type_update_tr( + +) RETURNS trigger AS $$ +DECLARE v_parent_sk varbit default null; v_max_value integer; v_rec record; - clr_keys_p boolean default ''t''; -begin + clr_keys_p boolean default 't'; +BEGIN if new.object_type = old.object_type and ((new.supertype = old.supertype) or (new.supertype is null and old.supertype is null)) then @@ -107,7 +132,7 @@ if clr_keys_p then update acs_object_types set tree_sortkey = null where tree_sortkey between new.tree_sortkey and tree_right(new.tree_sortkey); - clr_keys_p := ''f''; + clr_keys_p := 'f'; end if; select max(tree_leaf_key_to_int(tree_sortkey)) into v_max_value @@ -126,7 +151,8 @@ return new; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; create trigger acs_object_type_update_tr after update on acs_object_types @@ -569,23 +595,33 @@ -- METADATA PACKAGES -- ----------------------- -select define_function_args('acs_object_type__create_type','object_type,pretty_name,pretty_plural,supertype,table_name,id_column,package_name,abstract_p;f,type_extension_table,name_method,create_table_p;f,dynamic_p;f'); -create or replace function acs_object_type__create_type (varchar,varchar,varchar,varchar,varchar,varchar,varchar,boolean,varchar,varchar, boolean, boolean) -returns integer as ' -declare - p_object_type alias for $1; - p_pretty_name alias for $2; - p_pretty_plural alias for $3; - p_supertype alias for $4; - p_table_name alias for $5; -- default null - p_id_column alias for $6; -- default null - p_package_name alias for $7; -- default null - p_abstract_p alias for $8; -- default ''f'' - p_type_extension_table alias for $9; -- default null - p_name_method alias for $10; -- default null - p_create_table_p alias for $11; -- default ''f'' - p_dynamic_p alias for $12; -- default ''f'' +-- old define_function_args('acs_object_type__create_type','object_type,pretty_name,pretty_plural,supertype,table_name,id_column,package_name,abstract_p;f,type_extension_table,name_method,create_table_p;f,dynamic_p;f') +-- new +select define_function_args('acs_object_type__create_type','object_type,pretty_name,pretty_plural,supertype,table_name;null,id_column;null,package_name;null,abstract_p;f,type_extension_table;null,name_method;null,create_table_p;f,dynamic_p;f'); + + + + +-- +-- procedure acs_object_type__create_type/12 +-- +CREATE OR REPLACE FUNCTION acs_object_type__create_type( + p_object_type varchar, + p_pretty_name varchar, + p_pretty_plural varchar, + p_supertype varchar, + p_table_name varchar, -- default null + p_id_column varchar, -- default null + p_package_name varchar, -- default null + p_abstract_p boolean, -- default 'f' + p_type_extension_table varchar, -- default null + p_name_method varchar, -- default null + p_create_table_p boolean, -- default 'f' + p_dynamic_p boolean -- default 'f' + +) RETURNS integer AS $$ +DECLARE v_package_name acs_object_types.package_name%TYPE; v_supertype acs_object_types.supertype%TYPE; v_name_method varchar; @@ -594,11 +630,11 @@ v_supertype_table acs_object_types.table_name%TYPE; v_id_column acs_object_types.id_column%TYPE; v_table_name acs_object_types.table_name%TYPE; -begin - v_idx := position(''.'' in p_name_method); +BEGIN + v_idx := position('.' in p_name_method); if v_idx <> 0 then v_name_method := substr(p_name_method,1,v_idx - 1) || - ''__'' || substr(p_name_method, v_idx + 1); + '__' || substr(p_name_method, v_idx + 1); else v_name_method := p_name_method; end if; @@ -608,31 +644,31 @@ -- name. This code appends "_t" (for "table") because the use of english plural rules -- does not work well for all languages. - if p_create_table_p and (p_table_name is null or p_table_name = '''') then - v_table_name := p_object_type || ''_t''; + if p_create_table_p and (p_table_name is null or p_table_name = '') then + v_table_name := p_object_type || '_t'; else v_table_name := p_table_name; end if; - if p_create_table_p and (p_id_column is null or p_id_column = '''') then - v_id_column := p_object_type || ''_id''; + if p_create_table_p and (p_id_column is null or p_id_column = '') then + v_id_column := p_object_type || '_id'; else v_id_column := p_id_column; end if; - if p_package_name is null or p_package_name = '''' then + if p_package_name is null or p_package_name = '' then v_package_name := p_object_type; else v_package_name := p_package_name; end if; - if p_object_type <> ''acs_object'' then - if p_supertype is null or p_supertype = '''' then - v_supertype := ''acs_object''; + if p_object_type <> 'acs_object' then + if p_supertype is null or p_supertype = '' then + v_supertype := 'acs_object'; else v_supertype := p_supertype; - if not acs_object_type__is_subtype_p(''acs_object'', p_supertype) then - raise exception ''%s is not a valid type'', p_supertype; + if not acs_object_type__is_subtype_p('acs_object', p_supertype) then + raise exception '%s is not a valid type', p_supertype; end if; end if; end if; @@ -653,7 +689,7 @@ if exists (select 1 from pg_class where relname = lower(v_table_name)) then - raise exception ''Table "%" already exists'', v_table_name; + raise exception 'Table "%" already exists', v_table_name; end if; loop @@ -663,58 +699,79 @@ exit when v_supertype_table is not null; end loop; - execute ''create table '' || v_table_name || '' ('' || - v_id_column || '' integer constraint '' || v_table_name || - ''_pk primary key '' || '' constraint '' || v_table_name || - ''_fk references '' || v_supertype_table || '' on delete cascade)''; + execute 'create table ' || v_table_name || ' (' || + v_id_column || ' integer constraint ' || v_table_name || + '_pk primary key ' || ' constraint ' || v_table_name || + '_fk references ' || v_supertype_table || ' on delete cascade)'; end if; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- DRB: backwards compatibility version, don't allow for table creation. -create or replace function acs_object_type__create_type (varchar,varchar,varchar,varchar,varchar,varchar,varchar,boolean,varchar,varchar) -returns integer as ' -declare - p_object_type alias for $1; - p_pretty_name alias for $2; - p_pretty_plural alias for $3; - p_supertype alias for $4; - p_table_name alias for $5; -- default null - p_id_column alias for $6; -- default null - p_package_name alias for $7; -- default null - p_abstract_p alias for $8; -- default ''f'' - p_type_extension_table alias for $9; -- default null - p_name_method alias for $10; -- default null -begin + + +-- +-- procedure acs_object_type__create_type/10 +-- +CREATE OR REPLACE FUNCTION acs_object_type__create_type( + p_object_type varchar, + p_pretty_name varchar, + p_pretty_plural varchar, + p_supertype varchar, + p_table_name varchar, -- default null + p_id_column varchar, -- default null + p_package_name varchar, -- default null + p_abstract_p boolean, -- default 'f' + p_type_extension_table varchar, -- default null + p_name_method varchar -- default null + +) RETURNS integer AS $$ +-- +-- acs_object_type__create_type/10 maybe obsolete, when we define proper defaults for /12 +-- +DECLARE +BEGIN return acs_object_type__create_type(p_object_type, p_pretty_name, p_pretty_plural, p_supertype, p_table_name, p_id_column, p_package_name, p_abstract_p, - p_type_extension_table, p_name_method,''f'',''f''); -end;' language 'plpgsql'; + p_type_extension_table, p_name_method,'f','f'); +END; +$$ LANGUAGE plpgsql; -select define_function_args('acs_object_type__drop_type','object_type,drop_table_p;f,drop_children_p;f'); +-- old define_function_args('acs_object_type__drop_type','object_type,drop_table_p;f,drop_children_p;f') +-- new +select define_function_args('acs_object_type__drop_type','object_type,drop_children_p;f,drop_table_p;f'); + + -- procedure drop_type -create or replace function acs_object_type__drop_type (varchar,boolean,boolean) -returns integer as ' -declare - p_object_type alias for $1; - p_drop_children_p alias for $2; - p_drop_table_p alias for $3; + + +-- +-- procedure acs_object_type__drop_type/3 +-- +CREATE OR REPLACE FUNCTION acs_object_type__drop_type( + p_object_type varchar, + p_drop_children_p boolean, -- default 'f' + p_drop_table_p boolean -- default 'f' + +) RETURNS integer AS $$ +DECLARE row record; object_row record; v_table_name acs_object_types.table_name%TYPE; -begin +BEGIN -- drop children recursively if p_drop_children_p then for row in select object_type from acs_object_types where supertype = p_object_type loop - perform acs_object_type__drop_type(row.object_type, ''t'', p_drop_table_p); + perform acs_object_type__drop_type(row.object_type, 't', p_drop_table_p); end loop; end if; @@ -738,10 +795,10 @@ if not exists (select 1 from pg_class where relname = lower(v_table_name)) then - raise exception ''Table "%" does not exist'', v_table_name; + raise exception 'Table "%" does not exist', v_table_name; end if; - execute ''drop table '' || v_table_name || '' cascade''; + execute 'drop table ' || v_table_name || ' cascade'; end if; end if; @@ -750,40 +807,58 @@ where object_type = p_object_type; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- Retained for backwards compatibility -create or replace function acs_object_type__drop_type (varchar,boolean) -returns integer as ' -begin - return acs_object_type__drop_type($1,$2,''f''); -end;' language 'plpgsql'; +CREATE OR REPLACE FUNCTION acs_object_type__drop_type (varchar,boolean) RETURNS integer AS $$ +BEGIN + return acs_object_type__drop_type($1,$2,'f'); +END; +$$ LANGUAGE plpgsql; -- function pretty_name -create or replace function acs_object_type__pretty_name (varchar) -returns varchar as ' -declare - pretty_name__object_type alias for $1; + + +-- added +select define_function_args('acs_object_type__pretty_name','object_type'); + +-- +-- procedure acs_object_type__pretty_name/1 +-- +CREATE OR REPLACE FUNCTION acs_object_type__pretty_name( + pretty_name__object_type varchar +) RETURNS varchar AS $$ +DECLARE v_pretty_name acs_object_types.pretty_name%TYPE; -begin +BEGIN select t.pretty_name into v_pretty_name from acs_object_types t where t.object_type = pretty_name__object_type; return v_pretty_name; -end;' language 'plpgsql' stable strict; +END; +$$ LANGUAGE plpgsql stable strict; -- function is_subtype_p -create or replace function acs_object_type__is_subtype_p (varchar,varchar) -returns boolean as ' -declare - is_subtype_p__object_type_1 alias for $1; - is_subtype_p__object_type_2 alias for $2; + + +-- added +select define_function_args('acs_object_type__is_subtype_p','object_type_1,object_type_2'); + +-- +-- procedure acs_object_type__is_subtype_p/2 +-- +CREATE OR REPLACE FUNCTION acs_object_type__is_subtype_p( + is_subtype_p__object_type_1 varchar, + is_subtype_p__object_type_2 varchar +) RETURNS boolean AS $$ +DECLARE v_result integer; -begin +BEGIN select count(*) into v_result where exists (select 1 from acs_object_types t, acs_object_types t2 @@ -792,39 +867,50 @@ and t.tree_sortkey between t2.tree_sortkey and tree_right(t2.tree_sortkey)); if v_result > 0 then - return ''t''; + return 't'; end if; - return ''f''; + return 'f'; -end;' language 'plpgsql' stable; +END; +$$ LANGUAGE plpgsql stable; -select define_function_args('acs_attribute__create_attribute','object_type,attribute_name,datatype,pretty_name,pretty_plural,table_name,column_name,default_value,min_n_values;1,max_n_values;1,sort_order,storage;type_specific,static_p;f,create_column_p;f,database_type,size,null_p;t,references,check_expr,column_spec'); -create or replace function acs_attribute__create_attribute (varchar,varchar,varchar,varchar,varchar,varchar,varchar,varchar,integer,integer,integer,varchar,boolean,boolean,varchar,varchar,boolean,varchar,varchar,varchar) -returns integer as ' -declare - p_object_type alias for $1; - p_attribute_name alias for $2; - p_datatype alias for $3; - p_pretty_name alias for $4; - p_pretty_plural alias for $5; -- default null - p_table_name alias for $6; -- default null - p_column_name alias for $7; -- default null - p_default_value alias for $8; -- default null - p_min_n_values alias for $9; -- default 1 - p_max_n_values alias for $10; -- default 1 - p_sort_order alias for $11; -- default null - p_storage alias for $12; -- default ''type_specific'' - p_static_p alias for $13; -- default ''f'' - p_create_column_p alias for $14; -- default ''f'' - p_database_type alias for $15; -- default null - p_size alias for $16; -- default null - p_null_p alias for $17; -- default ''t'' - p_references alias for $18; -- default null - p_check_expr alias for $19; -- default null - p_column_spec alias for $20; -- default null +-- old define_function_args('acs_attribute__create_attribute','object_type,attribute_name,datatype,pretty_name,pretty_plural,table_name,column_name,default_value,min_n_values;1,max_n_values;1,sort_order,storage;type_specific,static_p;f,create_column_p;f,database_type,size,null_p;t,references,check_expr,column_spec') +-- new +select define_function_args('acs_attribute__create_attribute','object_type,attribute_name,datatype,pretty_name,pretty_plural;null,table_name;null,column_name;null,default_value;null,min_n_values;1,max_n_values;1,sort_order;null,storage;type_specific,static_p;f,create_column_p;f,database_type;null,size;null,null_p;t,references;null,check_expr;null,column_spec;null'); + + + +-- +-- procedure acs_attribute__create_attribute/20 +-- +CREATE OR REPLACE FUNCTION acs_attribute__create_attribute( + p_object_type varchar, + p_attribute_name varchar, + p_datatype varchar, + p_pretty_name varchar, + p_pretty_plural varchar, -- default null + p_table_name varchar, -- default null + p_column_name varchar, -- default null + p_default_value varchar, -- default null + p_min_n_values integer, -- default 1 -- default '1' + p_max_n_values integer, -- default 1 -- default '1' + p_sort_order integer, -- default null + p_storage varchar, -- default 'type_specific' + p_static_p boolean, -- default 'f' + p_create_column_p boolean, -- default 'f' + p_database_type varchar, -- default null + p_size varchar, -- default null + p_null_p boolean, -- default 't' + p_references varchar, -- default null + p_check_expr varchar, -- default null + p_column_spec varchar -- default null + +) RETURNS integer AS $$ +DECLARE + v_sort_order acs_attributes.sort_order%TYPE; v_attribute_id acs_attributes.attribute_id%TYPE; v_column_spec text; @@ -833,12 +919,12 @@ v_column_name text; v_datatype record; -begin +BEGIN if not exists (select 1 from acs_object_types where object_type = p_object_type) then - raise exception ''Object type % does not exist'', p_object_type; + raise exception 'Object type % does not exist', p_object_type; end if; if p_sort_order is null then @@ -850,7 +936,7 @@ v_sort_order := p_sort_order; end if; - select nextval(''t_acs_attribute_id_seq'') into v_attribute_id; + select nextval('t_acs_attribute_id_seq') into v_attribute_id; insert into acs_attributes (attribute_id, object_type, table_name, column_name, attribute_name, @@ -873,7 +959,7 @@ if not exists (select 1 from pg_class where relname = lower(v_table_name)) then - raise exception ''Table % for object type % does not exist'', v_table_name, p_object_type; + raise exception 'Table % for object type % does not exist', v_table_name, p_object_type; end if; -- Add the appropriate column to the table @@ -883,30 +969,30 @@ -- 2. the attribute is not declared static -- 3. it does not already exist in the table - if p_storage <> ''type_specific'' then - raise exception ''Attribute % for object type % must be declared with type_specific storage'', + if p_storage <> 'type_specific' then + raise exception 'Attribute % for object type % must be declared with type_specific storage', p_attribute_name, p_object_type; end if; if p_static_p then - raise exception ''Attribute % for object type % can not be declared static'', + raise exception 'Attribute % for object type % can not be declared static', p_attribute_name, p_object_type; end if; if p_table_name is not null then - raise exception ''Attribute % for object type % can not specify a table for storage'', p_attribute_name, p_object_type; + raise exception 'Attribute % for object type % can not specify a table for storage', p_attribute_name, p_object_type; end if; if exists (select 1 from pg_class c, pg_attribute a where c.relname::varchar = v_table_name and c.oid = a.attrelid and a.attname = lower(p_attribute_name)) then - raise exception ''Column % for object type % already exists'', + raise exception 'Column % for object type % already exists', p_attribute_name, p_object_type; end if; - -- all conditions for creating this column have been met, now let''s see if the type + -- all conditions for creating this column have been met, now let's see if the type -- spec is OK if p_column_spec is not null then @@ -915,7 +1001,7 @@ or p_null_p is not null or p_references is not null or p_check_expr is not null then - raise exception ''Attribute % for object type % is being created with an explicit column_spec, but not all of the type modification fields are null'', + raise exception 'Attribute % for object type % is being created with an explicit column_spec, but not all of the type modification fields are null', p_attribute_name, p_object_type; end if; v_column_spec := p_column_spec; @@ -930,94 +1016,111 @@ v_column_spec := v_datatype.database_type; if v_datatype.column_size is not null then - v_column_spec := v_column_spec || ''('' || v_datatype.column_size || '')''; + v_column_spec := v_column_spec || '(' || v_datatype.column_size || ')'; end if; - v_constraint_stub := '' constraint '' || p_object_type || ''_'' || - p_attribute_name || ''_''; + v_constraint_stub := ' constraint ' || p_object_type || '_' || + p_attribute_name || '_'; if v_datatype.check_expr is not null then - v_column_spec := v_column_spec || v_constraint_stub || ''ck check('' || - p_attribute_name || v_datatype.check_expr || '')''; + v_column_spec := v_column_spec || v_constraint_stub || 'ck check(' || + p_attribute_name || v_datatype.check_expr || ')'; end if; if not p_null_p then - v_column_spec := v_column_spec || v_constraint_stub || ''nn not null''; + v_column_spec := v_column_spec || v_constraint_stub || 'nn not null'; end if; if p_references is not null then - v_column_spec := v_column_spec || v_constraint_stub || ''fk references '' || - p_references || '' on delete''; + v_column_spec := v_column_spec || v_constraint_stub || 'fk references ' || + p_references || ' on delete'; if p_null_p then - v_column_spec := v_column_spec || '' set null''; + v_column_spec := v_column_spec || ' set null'; else - v_column_spec := v_column_spec || '' cascade''; + v_column_spec := v_column_spec || ' cascade'; end if; end if; end if; - execute ''alter table '' || v_table_name || '' add '' || p_attribute_name || '' '' || + execute 'alter table ' || v_table_name || ' add ' || p_attribute_name || ' ' || v_column_spec; end if; return v_attribute_id; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create or replace function acs_attribute__create_attribute (varchar,varchar,varchar,varchar,varchar,varchar,varchar,varchar,integer,integer,integer,varchar,boolean) -returns integer as ' -declare - p_object_type alias for $1; - p_attribute_name alias for $2; - p_datatype alias for $3; - p_pretty_name alias for $4; - p_pretty_plural alias for $5; -- default null - p_table_name alias for $6; -- default null - p_column_name alias for $7; -- default null - p_default_value alias for $8; -- default null - p_min_n_values alias for $9; -- default 1 - p_max_n_values alias for $10; -- default 1 - p_sort_order alias for $11; -- default null - p_storage alias for $12; -- default ''type_specific'' - p_static_p alias for $13; -- default ''f'' -begin + + +-- +-- procedure acs_attribute__create_attribute/13 +-- +CREATE OR REPLACE FUNCTION acs_attribute__create_attribute( + p_object_type varchar, + p_attribute_name varchar, + p_datatype varchar, + p_pretty_name varchar, + p_pretty_plural varchar, -- default null + p_table_name varchar, -- default null + p_column_name varchar, -- default null + p_default_value varchar, -- default null + p_min_n_values integer, -- default 1 + p_max_n_values integer, -- default 1 + p_sort_order integer, -- default null + p_storage varchar, -- default 'type_specific' + p_static_p boolean -- default 'f' + +) RETURNS integer AS $$ +-- +-- acs_attribute__create_attribute/13 maybe obsolete, when we define proper defaults for /20 +-- +DECLARE +BEGIN return acs_attribute__create_attribute(p_object_type, p_attribute_name, p_datatype, p_pretty_name, p_pretty_plural, p_table_name, p_column_name, p_default_value, p_min_n_values, p_max_n_values, p_sort_order, p_storage, - p_static_p, ''f'', null, null, null, null, null, null); -end;' language 'plpgsql'; + p_static_p, 'f', null, null, null, null, null, null); +END; +$$ LANGUAGE plpgsql; -create or replace function acs_attribute__create_attribute (varchar,varchar,varchar,varchar,varchar,varchar,varchar,integer,integer,integer,integer,varchar,boolean) -returns integer as ' -begin +CREATE OR REPLACE FUNCTION acs_attribute__create_attribute (varchar,varchar,varchar,varchar,varchar,varchar,varchar,integer,integer,integer,integer,varchar,boolean) RETURNS integer AS $$ +BEGIN return acs_attribute__create_attribute ($1, $2, $3, $4, $5, $6, $7, cast ($8 as varchar), $9, $10, $11, $12, $13); -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure drop_attribute select define_function_args('acs_attribute__drop_attribute','object_type,attribute_name,drop_column_p;f'); -create or replace function acs_attribute__drop_attribute (varchar,varchar,boolean) -returns integer as ' -declare - p_object_type alias for $1; - p_attribute_name alias for $2; - p_drop_column_p alias for $3; + + +-- +-- procedure acs_attribute__drop_attribute/3 +-- +CREATE OR REPLACE FUNCTION acs_attribute__drop_attribute( + p_object_type varchar, + p_attribute_name varchar, + p_drop_column_p boolean -- default 'f' + +) RETURNS integer AS $$ +DECLARE v_table_name acs_object_types.table_name%TYPE; -begin +BEGIN - -- Check that attribute exists and simultaneously grab the type''s table name + -- Check that attribute exists and simultaneously grab the type's table name select t.table_name into v_table_name from acs_object_types t, acs_attributes a where a.object_type = p_object_type and a.attribute_name = p_attribute_name and t.object_type = p_object_type; if not found then - raise exception ''Attribute %:% does not exist'', p_object_type, p_attribute_name; + raise exception 'Attribute %:% does not exist', p_object_type, p_attribute_name; end if; -- first remove possible values for the enumeration @@ -1027,10 +1130,10 @@ where a.object_type = p_object_type and a.attribute_name = p_attribute_name); - -- Drop the table if one were specified for the type and we''re asked to + -- Drop the table if one were specified for the type and we're asked to if p_drop_column_p and v_table_name is not null then - execute ''alter table '' || v_table_name || '' drop column '' || - p_attribute_name || '' cascade''; + execute 'alter table ' || v_table_name || ' drop column ' || + p_attribute_name || ' cascade'; end if; -- Finally, get rid of the attribute @@ -1039,65 +1142,96 @@ and attribute_name = p_attribute_name; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create or replace function acs_attribute__drop_attribute (varchar,varchar) -returns integer as ' -begin - return acs_attribute__drop_attribute($1, $2, ''f''); -end;' language 'plpgsql'; +CREATE OR REPLACE FUNCTION acs_attribute__drop_attribute (varchar,varchar) RETURNS integer AS $$ +BEGIN + return acs_attribute__drop_attribute($1, $2, 'f'); +END; +$$ LANGUAGE plpgsql; select define_function_args('acs_attribute__add_description','object_type,attribute_name,description_key,description'); -- procedure add_description -create function acs_attribute__add_description (varchar,varchar,varchar,text) -returns integer as ' -declare - add_description__object_type alias for $1; - add_description__attribute_name alias for $2; - add_description__description_key alias for $3; - add_description__description alias for $4; -begin + + +-- +-- procedure acs_attribute__add_description/4 +-- +CREATE OR REPLACE FUNCTION acs_attribute__add_description( + add_description__object_type varchar, + add_description__attribute_name varchar, + add_description__description_key varchar, + add_description__description text +) RETURNS integer AS $$ +DECLARE +BEGIN insert into acs_attribute_descriptions (object_type, attribute_name, description_key, description) values (add_description__object_type, add_description__attribute_name, add_description__description_key, add_description__description); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select define_function_args('acs_attribute__drop_description','object_type,attribute_name,description_key'); -- procedure drop_description -create function acs_attribute__drop_description (varchar,varchar,varchar) -returns integer as ' -declare - drop_description__object_type alias for $1; - drop_description__attribute_name alias for $2; - drop_description__description_key alias for $3; -begin + + +-- +-- procedure acs_attribute__drop_description/3 +-- +CREATE OR REPLACE FUNCTION acs_attribute__drop_description( + drop_description__object_type varchar, + drop_description__attribute_name varchar, + drop_description__description_key varchar +) RETURNS integer AS $$ +DECLARE +BEGIN delete from acs_attribute_descriptions where object_type = drop_description__object_type and attribute_name = drop_description__attribute_name and description_key = drop_description__description_key; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create or replace function acs_datatype__date_output_function(text) -returns text as ' -declare - p_attribute_name alias for $1; -begin - return ''to_char('' || p_attribute_name || '', ''''YYYY-MM-DD'''')''; -end;' language 'plpgsql'; -create or replace function acs_datatype__timestamp_output_function(text) -returns text as ' -declare - p_attribute_name alias for $1; -begin - return ''to_char('' || p_attribute_name || '', ''''YYYY-MM-DD HH24:MI:SS'''')''; -end;' language 'plpgsql'; +-- added +select define_function_args('acs_datatype__date_output_function','attribute_name'); + +-- +-- procedure acs_datatype__date_output_function/1 +-- +CREATE OR REPLACE FUNCTION acs_datatype__date_output_function( + p_attribute_name text +) RETURNS text AS $$ +DECLARE +BEGIN + return 'to_char(' || p_attribute_name || ', ''YYYY-MM-DD'')'; +END; +$$ LANGUAGE plpgsql; + + + +-- added +select define_function_args('acs_datatype__timestamp_output_function','attribute_name'); + +-- +-- procedure acs_datatype__timestamp_output_function/1 +-- +CREATE OR REPLACE FUNCTION acs_datatype__timestamp_output_function( + p_attribute_name text +) RETURNS text AS $$ +DECLARE +BEGIN + return 'to_char(' || p_attribute_name || ', ''YYYY-MM-DD HH24:MI:SS'')'; +END; +$$ LANGUAGE plpgsql; + -- show errors Index: openacs-4/packages/acs-kernel/sql/postgresql/acs-object-util.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/postgresql/acs-object-util.sql,v diff -u -r1.4 -r1.5 --- openacs-4/packages/acs-kernel/sql/postgresql/acs-object-util.sql 11 Dec 2003 21:39:52 -0000 1.4 +++ openacs-4/packages/acs-kernel/sql/postgresql/acs-object-util.sql 7 Jul 2011 10:46:02 -0000 1.5 @@ -1,86 +1,131 @@ -- moved from site-wide search to acs-kernel -create or replace function acs_object_util__object_type_exist_p (varchar) -returns boolean as ' -declare - p_object_type alias for $1; - v_exist_p boolean := ''t''; -begin - select (case when count(*)=1 then ''t'' else ''f'' end) into v_exist_p +-- added +select define_function_args('acs_object_util__object_type_exist_p','object_type'); + +-- +-- procedure acs_object_util__object_type_exist_p/1 +-- +CREATE OR REPLACE FUNCTION acs_object_util__object_type_exist_p( + p_object_type varchar +) RETURNS boolean AS $$ +DECLARE + v_exist_p boolean := 't'; +BEGIN + + + select (case when count(*)=1 then 't' else 'f' end) into v_exist_p from acs_object_types where object_type = p_object_type; return v_exist_p; -end;' language 'plpgsql' stable; +END; +$$ LANGUAGE plpgsql stable; -create or replace function acs_object_util__get_object_type (integer) -returns varchar as ' -declare - p_object_id alias for $1; + + +-- added +select define_function_args('acs_object_util__get_object_type','object_id'); + +-- +-- procedure acs_object_util__get_object_type/1 +-- +CREATE OR REPLACE FUNCTION acs_object_util__get_object_type( + p_object_id integer +) RETURNS varchar AS $$ +DECLARE v_object_type varchar(100); -begin +BEGIN select object_type into v_object_type from acs_objects where object_id = p_object_id; if not found then - raise exception ''acs_object_util__get_object_type: Invalid Object id: % '', p_object_id; + raise exception 'acs_object_util__get_object_type: Invalid Object id: % ', p_object_id; end if; return v_object_type; -end;' language 'plpgsql' stable; +END; +$$ LANGUAGE plpgsql stable; -create or replace function acs_object_util__type_ancestor_type_p (varchar,varchar) -returns boolean as ' -declare - p_object_type1 alias for $1; - p_object_type2 alias for $2; -begin + +-- added +select define_function_args('acs_object_util__type_ancestor_type_p','object_type1,object_type2'); + +-- +-- procedure acs_object_util__type_ancestor_type_p/2 +-- +CREATE OR REPLACE FUNCTION acs_object_util__type_ancestor_type_p( + p_object_type1 varchar, + p_object_type2 varchar +) RETURNS boolean AS $$ +DECLARE +BEGIN + if not acs_object_util__object_type_exist_p(p_object_type1) then - raise exception ''Object type % does not exist'', p_object_type1; + raise exception 'Object type % does not exist', p_object_type1; end if; if not acs_object_util__object_type_exist_p(p_object_type2) then - raise exception ''Object type % does not exist'', p_object_type2; + raise exception 'Object type % does not exist', p_object_type2; end if; return exists (select 1 from acs_object_types o1, acs_object_types o2 where p_object_type2 = o2.object_type and o1.object_type = p_object_type1 and o1.tree_sortkey between o2.tree_sortkey and tree_right(o2.tree_sortkey)); -end;' language 'plpgsql' stable; +END; +$$ LANGUAGE plpgsql stable; -create or replace function acs_object_util__object_ancestor_type_p (integer,varchar) -returns boolean as ' -declare - p_object_id alias for $1; - p_object_type alias for $2; - v_exist_p boolean := ''f''; + + +-- added +select define_function_args('acs_object_util__object_ancestor_type_p','object_id,object_type'); + +-- +-- procedure acs_object_util__object_ancestor_type_p/2 +-- +CREATE OR REPLACE FUNCTION acs_object_util__object_ancestor_type_p( + p_object_id integer, + p_object_type varchar +) RETURNS boolean AS $$ +DECLARE + v_exist_p boolean := 'f'; v_object_type varchar(100); -begin +BEGIN v_object_type := acs_object_util__get_object_type (p_object_id); v_exist_p := acs_object_util__type_ancestor_type_p (v_object_type, p_object_type); return v_exist_p; -end;' language 'plpgsql' stable; +END; +$$ LANGUAGE plpgsql stable; -create or replace function acs_object_util__object_type_p (integer,varchar) -returns boolean as ' -declare - p_object_id alias for $1; - p_object_type alias for $2; - v_exist_p boolean := ''f''; -begin + + +-- added +select define_function_args('acs_object_util__object_type_p','object_id,object_type'); + +-- +-- procedure acs_object_util__object_type_p/2 +-- +CREATE OR REPLACE FUNCTION acs_object_util__object_type_p( + p_object_id integer, + p_object_type varchar +) RETURNS boolean AS $$ +DECLARE + v_exist_p boolean := 'f'; +BEGIN v_exist_p := acs_object_util__object_ancestor_type_p(p_object_id, p_object_type); return v_exist_p; -end;' language 'plpgsql' stable; +END; +$$ LANGUAGE plpgsql stable; Index: openacs-4/packages/acs-kernel/sql/postgresql/acs-objects-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/postgresql/acs-objects-create.sql,v diff -u -r1.63 -r1.64 --- openacs-4/packages/acs-kernel/sql/postgresql/acs-objects-create.sql 17 Oct 2010 21:06:08 -0000 1.63 +++ openacs-4/packages/acs-kernel/sql/postgresql/acs-objects-create.sql 7 Jul 2011 10:46:02 -0000 1.64 @@ -17,189 +17,196 @@ -- PREDEFINED OBJECT TYPES -- ----------------------------- -create function inline_0 () -returns integer as ' -declare + + +-- +-- procedure inline_0/0 +-- +CREATE OR REPLACE FUNCTION inline_0( + +) RETURNS integer AS $$ +DECLARE attr_id acs_attributes.attribute_id%TYPE; -begin +BEGIN -- -- The ultimate supertype: object -- PERFORM acs_object_type__create_type ( - ''acs_object'', - ''Object'', - ''Objects'', + 'acs_object', + 'Object', + 'Objects', null, - ''acs_objects'', - ''object_id'', - ''acs_object'', - ''f'', + 'acs_objects', + 'object_id', + 'acs_object', + 'f', null, - ''acs_object.default_name'' + 'acs_object.default_name' ); attr_id := acs_attribute__create_attribute ( - ''acs_object'', - ''object_type'', - ''string'', - ''Object Type'', - ''Object Types'', + 'acs_object', + 'object_type', + 'string', + 'Object Type', + 'Object Types', null, null, null, 1, 1, null, - ''type_specific'', - ''f'' + 'type_specific', + 'f' ); attr_id := acs_attribute__create_attribute ( - ''acs_object'', - ''creation_date'', - ''date'', - ''Created Date'', + 'acs_object', + 'creation_date', + 'date', + 'Created Date', null, null, null, null, 1, 1, null, - ''type_specific'', - ''f'' + 'type_specific', + 'f' ); attr_id := acs_attribute__create_attribute ( - ''acs_object'', - ''creation_ip'', - ''string'', - ''Creation IP Address'', + 'acs_object', + 'creation_ip', + 'string', + 'Creation IP Address', null, null, null, null, 1, 1, null, - ''type_specific'', - ''f'' + 'type_specific', + 'f' ); attr_id := acs_attribute__create_attribute ( - ''acs_object'', - ''last_modified'', - ''date'', - ''Last Modified On'', + 'acs_object', + 'last_modified', + 'date', + 'Last Modified On', null, null, null, null, 1, 1, null, - ''type_specific'', - ''f'' + 'type_specific', + 'f' ); attr_id := acs_attribute__create_attribute ( - ''acs_object'', - ''modifying_ip'', - ''string'', - ''Modifying IP Address'', + 'acs_object', + 'modifying_ip', + 'string', + 'Modifying IP Address', null, null, null, null, 1, 1, null, - ''type_specific'', - ''f'' + 'type_specific', + 'f' ); attr_id := acs_attribute__create_attribute ( - ''acs_object'', - ''modifying_user'', - ''integer'', - ''Modifying User'', + 'acs_object', + 'modifying_user', + 'integer', + 'Modifying User', null, null, null, null, 1, 1, null, - ''type_specific'', - ''f'' + 'type_specific', + 'f' ); attr_id := acs_attribute__create_attribute ( - ''acs_object'', - ''creation_user'', - ''integer'', - ''Creation user'', - ''Creation users'', + 'acs_object', + 'creation_user', + 'integer', + 'Creation user', + 'Creation users', null, null, null, 0, 1, null, - ''type_specific'', - ''f'' + 'type_specific', + 'f' ); attr_id := acs_attribute__create_attribute ( - ''acs_object'', - ''context_id'', - ''integer'', - ''Context ID'', - ''Context IDs'', + 'acs_object', + 'context_id', + 'integer', + 'Context ID', + 'Context IDs', null, null, null, 0, 1, null, - ''type_specific'', - ''f'' + 'type_specific', + 'f' ); attr_id := acs_attribute__create_attribute ( - ''acs_object'', - ''package_id'', - ''integer'', - ''Package ID'', - ''Package IDs'', + 'acs_object', + 'package_id', + 'integer', + 'Package ID', + 'Package IDs', null, null, null, 0, 1, null, - ''type_specific'', - ''f'' + 'type_specific', + 'f' ); attr_id := acs_attribute__create_attribute ( - ''acs_object'', - ''title'', - ''string'', - ''Title'', - ''Titles'', + 'acs_object', + 'title', + 'string', + 'Title', + 'Titles', null, null, null, 0, 1, null, - ''type_specific'', - ''f'' + 'type_specific', + 'f' ); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select inline_0 (); @@ -258,46 +265,65 @@ create index acs_objects_object_type_idx on acs_objects (object_type); -create function acs_objects_mod_ip_insert_tr () returns trigger as ' -begin +CREATE OR REPLACE FUNCTION acs_objects_mod_ip_insert_tr () RETURNS trigger AS $$ +BEGIN new.modifying_ip := new.creation_ip; return new; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; create trigger acs_objects_mod_ip_insert_tr before insert on acs_objects for each row execute procedure acs_objects_mod_ip_insert_tr (); -- show errors -create function acs_objects_last_mod_update_tr () returns trigger as ' -begin +CREATE OR REPLACE FUNCTION acs_objects_last_mod_update_tr () RETURNS trigger AS $$ +BEGIN if new.last_modified is null then new.last_modified := old.last_modified; elsif new.last_modified = old.last_modified then new.last_modified := now(); end if; return new; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; create trigger acs_objects_last_mod_update_tr before update on acs_objects for each row execute procedure acs_objects_last_mod_update_tr (); -- tree query support for acs_objects -create or replace function acs_objects_get_tree_sortkey(integer) returns varbit as ' -declare - p_object_id alias for $1; -begin + + +-- added +select define_function_args('acs_objects_get_tree_sortkey','object_id'); + +-- +-- procedure acs_objects_get_tree_sortkey/1 +-- +CREATE OR REPLACE FUNCTION acs_objects_get_tree_sortkey( + p_object_id integer +) RETURNS varbit AS $$ +DECLARE +BEGIN return tree_sortkey from acs_objects where object_id = p_object_id; -end;' language 'plpgsql' stable strict; +END; +$$ LANGUAGE plpgsql stable strict; -create function acs_objects_insert_tr() returns trigger as ' -declare + + +-- +-- procedure acs_objects_insert_tr/0 +-- +CREATE OR REPLACE FUNCTION acs_objects_insert_tr( + +) RETURNS trigger AS $$ +DECLARE v_parent_sk varbit default null; v_max_child_sortkey varbit; -begin +BEGIN if new.context_id is null then new.tree_sortkey := int_to_tree_key(new.object_id+1000); else @@ -316,19 +342,27 @@ new.max_child_sortkey := null; return new; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; create trigger acs_objects_insert_tr before insert on acs_objects for each row execute procedure acs_objects_insert_tr (); -create function acs_objects_update_tr () returns trigger as ' -declare + + +-- +-- procedure acs_objects_update_tr/0 +-- +CREATE OR REPLACE FUNCTION acs_objects_update_tr( + +) RETURNS trigger AS $$ +DECLARE v_parent_sk varbit default null; v_max_child_sortkey varbit; v_old_parent_length integer; -begin +BEGIN if new.object_id = old.object_id and ((new.context_id = old.context_id) or (new.context_id is null @@ -363,7 +397,8 @@ WHERE tree_sortkey between new.tree_sortkey and tree_right(new.tree_sortkey); return new; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; create trigger acs_objects_update_tr after update on acs_objects @@ -438,16 +473,23 @@ from acs_object_context_index where object_id != ancestor_id; -create or replace function acs_objects_context_id_in_tr () returns trigger as ' -declare + + +-- +-- procedure acs_objects_context_id_in_tr/0 +-- +CREATE OR REPLACE FUNCTION acs_objects_context_id_in_tr( + +) RETURNS trigger AS $$ +DECLARE security_context_root integer; -begin +BEGIN insert into acs_object_context_index (object_id, ancestor_id, n_generations) values (new.object_id, new.object_id, 0); - if new.context_id is not null and new.security_inherit_p = ''t'' then + if new.context_id is not null and new.security_inherit_p = 't' then insert into acs_object_context_index (object_id, ancestor_id, n_generations) select @@ -456,7 +498,7 @@ from acs_object_context_index where object_id = new.context_id; else - security_context_root = acs__magic_object_id(''security_context_root''); + security_context_root = acs__magic_object_id('security_context_root'); if new.object_id != security_context_root then insert into acs_object_context_index (object_id, ancestor_id, n_generations) @@ -467,18 +509,26 @@ return new; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; create trigger acs_objects_context_id_in_tr after insert on acs_objects for each row execute procedure acs_objects_context_id_in_tr (); -create or replace function acs_objects_context_id_up_tr () returns trigger as ' -declare + + +-- +-- procedure acs_objects_context_id_up_tr/0 +-- +CREATE OR REPLACE FUNCTION acs_objects_context_id_up_tr( + +) RETURNS trigger AS $$ +DECLARE pair record; outer_record record; inner_record record; security_context_root integer; -begin +BEGIN if new.object_id = old.object_id and ((new.context_id = old.context_id) or (new.context_id is null and old.context_id is null)) @@ -506,7 +556,7 @@ values (new.object_id, new.object_id, 0); - if new.context_id is not null and new.security_inherit_p = ''t'' then + if new.context_id is not null and new.security_inherit_p = 't' then -- Now insert my new ancestors for my descendants. for pair in select * from acs_object_context_index @@ -521,7 +571,7 @@ where object_id = new.context_id; end loop; else - security_context_root = acs__magic_object_id(''security_context_root''); + security_context_root = acs__magic_object_id('security_context_root'); if new.object_id != security_context_root then -- We need to make sure that new.OBJECT_ID and all of its -- children have security_context_root as an ancestor. @@ -539,19 +589,21 @@ return new; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; create trigger acs_objects_context_id_up_tr after update on acs_objects for each row execute procedure acs_objects_context_id_up_tr (); -create function acs_objects_context_id_del_tr () returns trigger as ' -begin +CREATE OR REPLACE FUNCTION acs_objects_context_id_del_tr () RETURNS trigger AS $$ +BEGIN delete from acs_object_context_index where object_id = old.object_id; return old; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; create trigger acs_objects_context_id_del_tr before delete on acs_objects for each row execute procedure acs_objects_context_id_del_tr (); @@ -609,14 +661,19 @@ select define_function_args('acs_object__initialize_attributes','initialize_attributes__object_id'); -create or replace function acs_object__initialize_attributes (integer) -returns integer as ' -declare - initialize_attributes__object_id alias for $1; + + +-- +-- procedure acs_object__initialize_attributes/1 +-- +CREATE OR REPLACE FUNCTION acs_object__initialize_attributes( + initialize_attributes__object_id integer +) RETURNS integer AS $$ +DECLARE v_object_type acs_objects.object_type%TYPE; -begin +BEGIN if initialize_attributes__object_id is null then - raise exception ''acs_object__initialize_attributes called with null object_id''; + raise exception 'acs_object__initialize_attributes called with null object_id'; end if; -- Initialize dynamic attributes @@ -627,8 +684,8 @@ from acs_attributes a, acs_objects o where a.object_type = o.object_type and o.object_id = initialize_attributes__object_id - and a.storage = ''generic'' - and a.static_p = ''f''; + and a.storage = 'generic' + and a.static_p = 'f'; -- Retrieve type for static attributes select object_type into v_object_type from acs_objects @@ -643,38 +700,49 @@ from acs_attributes a, acs_objects o where a.object_type = o.object_type and o.object_id = initialize_attributes__object_id - and a.storage = ''generic'' - and a.static_p = ''t'' + and a.storage = 'generic' + and a.static_p = 't' and not exists (select 1 from acs_static_attr_values where object_type = a.object_type); -- exception when no_data_found then null; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function new -select define_function_args('acs_object__new','object_id,object_type;acs_object,creation_date,creation_user,creation_ip,context_id,security_inherit_p;t,title,package_id'); -create or replace function acs_object__new (integer,varchar,timestamptz,integer,varchar,integer,boolean,varchar,integer) -returns integer as ' -declare - new__object_id alias for $1; -- default null - new__object_type alias for $2; -- default ''acs_object'' - new__creation_date alias for $3; -- default now() - new__creation_user alias for $4; -- default null - new__creation_ip alias for $5; -- default null - new__context_id alias for $6; -- default null - new__security_inherit_p alias for $7; -- default ''t'' - new__title alias for $8; -- default null - new__package_id alias for $9; -- default null +-- old define_function_args('acs_object__new','object_id,object_type;acs_object,creation_date,creation_user,creation_ip,context_id,security_inherit_p;t,title,package_id') +-- new +select define_function_args('acs_object__new','object_id;null,object_type;acs_object,creation_date;now(),creation_user;null,creation_ip;null,context_id;null,security_inherit_p;t,title;null,package_id;null'); + + + + +-- +-- procedure acs_object__new/9 +-- +CREATE OR REPLACE FUNCTION acs_object__new( + new__object_id integer, -- default null + new__object_type varchar, -- default 'acs_object' + new__creation_date timestamptz, -- default now() + new__creation_user integer, -- default null + new__creation_ip varchar, -- default null + new__context_id integer, -- default null + new__security_inherit_p boolean, -- default 't' + new__title varchar, -- default null + new__package_id integer -- default null + +) RETURNS integer AS $$ +DECLARE v_object_id acs_objects.object_id%TYPE; v_creation_date timestamptz; v_title acs_objects.title%TYPE; v_object_type_pretty_name acs_object_types.pretty_name%TYPE; -begin +BEGIN if new__object_id is null then - select nextval(''t_acs_object_id_seq'') into v_object_id; + select nextval('t_acs_object_id_seq') into v_object_id; else v_object_id := new__object_id; end if; @@ -685,7 +753,7 @@ from acs_object_types where object_type = new__object_type; - v_title := v_object_type_pretty_name || '' '' || v_object_id; + v_title := v_object_type_pretty_name || ' ' || v_object_id; else v_title := new__title; end if; @@ -708,112 +776,179 @@ return v_object_id; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function new -create or replace function acs_object__new (integer,varchar,timestamptz,integer,varchar,integer) -returns integer as ' -declare - new__object_id alias for $1; -- default null - new__object_type alias for $2; -- default ''acs_object'' - new__creation_date alias for $3; -- default now() - new__creation_user alias for $4; -- default null - new__creation_ip alias for $5; -- default null - new__context_id alias for $6; -- default null + + +-- +-- procedure acs_object__new/6 +-- +CREATE OR REPLACE FUNCTION acs_object__new( + new__object_id integer, -- default null + new__object_type varchar, -- default 'acs_object' + new__creation_date timestamptz, -- default now() + new__creation_user integer, -- default null + new__creation_ip varchar, -- default null + new__context_id integer -- default null + +) RETURNS integer AS $$ +-- +-- acs_object__new/6 maybe obsolete, when we define proper defaults for /9 +-- +DECLARE v_object_id acs_objects.object_id%TYPE; v_creation_date timestamptz; -begin +BEGIN return acs_object__new(new__object_id, new__object_type, new__creation_date, new__creation_user, new__creation_ip, new__context_id, - ''t'', null, null); -end;' language 'plpgsql'; + 't', null, null); +END; +$$ LANGUAGE plpgsql; -create or replace function acs_object__new (integer,varchar,timestamptz,integer,varchar,integer,boolean) -returns integer as ' -declare - new__object_id alias for $1; -- default null - new__object_type alias for $2; -- default ''acs_object'' - new__creation_date alias for $3; -- default now() - new__creation_user alias for $4; -- default null - new__creation_ip alias for $5; -- default null - new__context_id alias for $6; -- default null - new__security_inherit_p alias for $7; -- default ''t'' -begin + + +-- +-- procedure acs_object__new/7 +-- +CREATE OR REPLACE FUNCTION acs_object__new( + new__object_id integer, -- default null + new__object_type varchar, -- default 'acs_object' + new__creation_date timestamptz, -- default now() + new__creation_user integer, -- default null + new__creation_ip varchar, -- default null + new__context_id integer, -- default null + new__security_inherit_p boolean -- default 't' + +) RETURNS integer AS $$ +-- +-- acs_object__new/7 maybe obsolete, when we define proper defaults for /9 +-- +DECLARE +BEGIN return acs_object__new(new__object_id, new__object_type, new__creation_date, new__creation_user, new__creation_ip, new__context_id, new__security_inherit_p, null, null); -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create or replace function acs_object__new (integer,varchar,timestamptz,integer,varchar,integer,boolean,varchar) -returns integer as ' -declare - new__object_id alias for $1; -- default null - new__object_type alias for $2; -- default ''acs_object'' - new__creation_date alias for $3; -- default now() - new__creation_user alias for $4; -- default null - new__creation_ip alias for $5; -- default null - new__context_id alias for $6; -- default null - new__security_inherit_p alias for $7; -- default ''t'' - new__title alias for $8; -- default null -begin + + +-- +-- procedure acs_object__new/8 +-- +CREATE OR REPLACE FUNCTION acs_object__new( + new__object_id integer, -- default null + new__object_type varchar, -- default 'acs_object' + new__creation_date timestamptz, -- default now() + new__creation_user integer, -- default null + new__creation_ip varchar, -- default null + new__context_id integer, -- default null + new__security_inherit_p boolean, -- default 't' + new__title varchar -- default null + +) RETURNS integer AS $$ +-- +-- acs_object__new/8 maybe obsolete, when we define proper defaults for /9 +-- +DECLARE +BEGIN return acs_object__new(new__object_id, new__object_type, new__creation_date, new__creation_user, new__creation_ip, new__context_id, new__security_inherit_p, new__title, null); -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create or replace function acs_object__new (integer,varchar,timestamptz,integer,varchar,integer,varchar,integer) -returns integer as ' -declare - new__object_id alias for $1; -- default null - new__object_type alias for $2; -- default ''acs_object'' - new__creation_date alias for $3; -- default now() - new__creation_user alias for $4; -- default null - new__creation_ip alias for $5; -- default null - new__context_id alias for $6; -- default null - new__title alias for $7; -- default null - new__package_id alias for $8; -- default null -begin + + +-- +-- procedure acs_object__new/8 +-- +CREATE OR REPLACE FUNCTION acs_object__new( + new__object_id integer, -- default null + new__object_type varchar, -- default 'acs_object' + new__creation_date timestamptz, -- default now() + new__creation_user integer, -- default null + new__creation_ip varchar, -- default null + new__context_id integer, -- default null + new__title varchar, -- default null + new__package_id integer -- default null + +) RETURNS integer AS $$ +-- +-- acs_object__new/8 maybe obsolete, when we define proper defaults for /9 +-- +DECLARE +BEGIN return acs_object__new(new__object_id, new__object_type, new__creation_date, new__creation_user, new__creation_ip, new__context_id, - ''t'', new__title, new__package_id); -end;' language 'plpgsql'; + 't', new__title, new__package_id); +END; +$$ LANGUAGE plpgsql; -create or replace function acs_object__new (integer,varchar,timestamptz,integer,varchar,integer,varchar) -returns integer as ' -declare - new__object_id alias for $1; -- default null - new__object_type alias for $2; -- default ''acs_object'' - new__creation_date alias for $3; -- default now() - new__creation_user alias for $4; -- default null - new__creation_ip alias for $5; -- default null - new__context_id alias for $6; -- default null - new__title alias for $7; -- default null -begin + + +-- +-- procedure acs_object__new/7 +-- +CREATE OR REPLACE FUNCTION acs_object__new( + new__object_id integer, -- default null + new__object_type varchar, -- default 'acs_object' + new__creation_date timestamptz, -- default now() + new__creation_user integer, -- default null + new__creation_ip varchar, -- default null + new__context_id integer, -- default null + new__title varchar -- default null + +) RETURNS integer AS $$ +-- +-- acs_object__new/7 maybe obsolete, when we define proper defaults for /9 +-- +DECLARE +BEGIN return acs_object__new(new__object_id, new__object_type, new__creation_date, new__creation_user, new__creation_ip, new__context_id, - ''t'', new__title, null); -end;' language 'plpgsql'; + 't', new__title, null); +END; +$$ LANGUAGE plpgsql; -create function acs_object__new (integer,varchar) returns integer as ' -declare - object_id alias for $1; -- default null - object_type alias for $2; -- default ''acs_object'' -begin + + +-- +-- procedure acs_object__new/2 +-- +CREATE OR REPLACE FUNCTION acs_object__new( + object_id integer, -- default null + object_type varchar -- default 'acs_object' + +) RETURNS integer AS $$ +-- +-- acs_object__new/2 maybe obsolete, when we define proper defaults for /9 +-- +DECLARE +BEGIN return acs_object__new(object_id,object_type,now(),null,null,null); -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure delete select define_function_args('acs_object__delete','object_id'); -create function acs_object__delete (integer) -returns integer as ' -declare - delete__object_id alias for $1; + + +-- +-- procedure acs_object__delete/1 +-- +CREATE OR REPLACE FUNCTION acs_object__delete( + delete__object_id integer +) RETURNS integer AS $$ +DECLARE obj_type record; -begin +BEGIN -- Delete dynamic/generic attributes delete from acs_attribute_values where object_id = delete__object_id; @@ -854,30 +989,36 @@ -- table name, so we need to check if the table exists. Wp-slim does this too if table_exists(obj_type.table_name) then - execute ''delete from '' || obj_type.table_name || - '' where '' || obj_type.id_column || '' = '' || delete__object_id; + execute 'delete from ' || obj_type.table_name || + ' where ' || obj_type.id_column || ' = ' || delete__object_id; end if; end loop; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function name select define_function_args('acs_object__name','name__object_id'); -create function acs_object__name (integer) -returns varchar as ' -declare - name__object_id alias for $1; + + +-- +-- procedure acs_object__name/1 +-- +CREATE OR REPLACE FUNCTION acs_object__name( + name__object_id integer +) RETURNS varchar AS $$ +DECLARE object_name varchar; v_object_id integer; obj_type record; obj record; -begin +BEGIN -- Find the name function for this object, which is stored in the -- name_method column of acs_object_types. Starting with this - -- object''s actual type, traverse the type hierarchy upwards until + -- object's actual type, traverse the type hierarchy upwards until -- a non-null name_method value is found. -- -- select name_method @@ -904,15 +1045,15 @@ and o1.tree_sortkey between o2.tree_sortkey and tree_right(o2.tree_sortkey) order by o2.tree_sortkey desc loop - if obj_type.name_method != '''' and obj_type.name_method is NOT null then + if obj_type.name_method != '' and obj_type.name_method is NOT null then - -- Execute the first name_method we find (since we''re traversing - -- up the type hierarchy from the object''s exact type) using + -- Execute the first name_method we find (since we're traversing + -- up the type hierarchy from the object's exact type) using -- Native Dynamic SQL, to ascertain the name of this object. -- - --execute ''select '' || object_type.name_method || ''(:1) from dual'' + --execute 'select ' || object_type.name_method || '(:1) from dual' - for obj in execute ''select '' || obj_type.name_method || ''('' || name__object_id || '')::varchar as object_name'' loop + for obj in execute 'select ' || obj_type.name_method || '(' || name__object_id || ')::varchar as object_name' loop object_name := obj.object_name; exit; end loop; @@ -923,40 +1064,55 @@ return object_name; -end;' language 'plpgsql' stable strict; +END; +$$ LANGUAGE plpgsql stable strict; -- function default_name select define_function_args('acs_object__default_name','default_name__object_id'); -create or replace function acs_object__default_name (integer) -returns varchar as ' -declare - default_name__object_id alias for $1; + + +-- +-- procedure acs_object__default_name/1 +-- +CREATE OR REPLACE FUNCTION acs_object__default_name( + default_name__object_id integer +) RETURNS varchar AS $$ +DECLARE object_type_pretty_name acs_object_types.pretty_name%TYPE; -begin +BEGIN select ot.pretty_name into object_type_pretty_name from acs_objects o, acs_object_types ot where o.object_id = default_name__object_id and o.object_type = ot.object_type; - return object_type_pretty_name || '' '' || default_name__object_id; + return object_type_pretty_name || ' ' || default_name__object_id; -end;' language 'plpgsql' stable strict; +END; +$$ LANGUAGE plpgsql stable strict; -- function package_id select define_function_args('acs_object__object_id','p_object_id'); -create or replace function acs_object__package_id (integer) -returns integer as ' -declare - p_object_id alias for $1; + + +-- added +select define_function_args('acs_object__package_id','object_id'); + +-- +-- procedure acs_object__package_id/1 +-- +CREATE OR REPLACE FUNCTION acs_object__package_id( + p_object_id integer +) RETURNS integer AS $$ +DECLARE v_package_id acs_objects.package_id%TYPE; -begin +BEGIN if p_object_id is null then return null; end if; @@ -966,19 +1122,25 @@ where object_id = p_object_id; return v_package_id; -end;' language 'plpgsql' stable strict; +END; +$$ LANGUAGE plpgsql stable strict; -- procedure get_attribute_storage select define_function_args('acs_object__get_attribute_storage','object_id_in,attribute_name_in'); -create or replace function acs_object__get_attribute_storage (integer,varchar) -returns text as ' -declare - object_id_in alias for $1; - attribute_name_in alias for $2; + +-- +-- procedure acs_object__get_attribute_storage/2 +-- +CREATE OR REPLACE FUNCTION acs_object__get_attribute_storage( + object_id_in integer, + attribute_name_in varchar +) RETURNS text AS $$ +DECLARE + -- these three are the out variables v_column varchar; v_table_name varchar; @@ -993,7 +1155,7 @@ v_sql text; v_return text; v_rec record; -begin +BEGIN -- select -- object_type, id_column -- from @@ -1026,36 +1188,36 @@ a.object_type = t.object_type; if NOT FOUND then - raise EXCEPTION ''-20000: No such attribute % for object % in acs_object.get_attribute_storage.'', attribute_name_in, object_id_in; + raise EXCEPTION '-20000: No such attribute % for object % in acs_object.get_attribute_storage.', attribute_name_in, object_id_in; end if; -- This should really be done in a trigger on acs_attributes, -- instead of generating it each time in this function -- If there is no specific table name for this attribute, -- figure it out based on the object type - if v_table_name is null or v_table_name = '''' then + if v_table_name is null or v_table_name = '' then -- Determine the appropriate table name - if v_storage = ''generic'' then + if v_storage = 'generic' then -- Generic attribute: table name/column are hardcoded - v_column := ''attr_value''; + v_column := 'attr_value'; - if v_static = ''f'' then - v_table_name := ''acs_attribute_values''; - v_key_sql := ''(object_id = '' || object_id_in || '' and '' || - ''attribute_id = '' || v_attr_id || '')''; + if v_static = 'f' then + v_table_name := 'acs_attribute_values'; + v_key_sql := '(object_id = ' || object_id_in || ' and ' || + 'attribute_id = ' || v_attr_id || ')'; else - v_table_name := ''acs_static_attr_values''; - v_key_sql := ''(object_type = '''''' || v_object_type || '''''' and '' || - ''attribute_id = '' || v_attr_id || '')''; + v_table_name := 'acs_static_attr_values'; + v_key_sql := '(object_type = ''' || v_object_type || ''' and ' || + 'attribute_id = ' || v_attr_id || ')'; end if; else -- Specific attribute: table name/column need to be retreived - if v_static = ''f'' then + if v_static = 'f' then select table_name, id_column into @@ -1065,10 +1227,10 @@ where object_type = v_object_type; if NOT FOUND then - raise EXCEPTION ''-20000: No data found for attribute %::% object_id % in acs_object.get_attribute_storage'', v_object_type, attribute_name_in, object_id_in; + raise EXCEPTION '-20000: No data found for attribute %::% object_id % in acs_object.get_attribute_storage', v_object_type, attribute_name_in, object_id_in; end if; else - raise EXCEPTION ''-20000: No table name specified for storage specific static attribute %::% object_id % in acs_object.get_attribute_storage.'',v_object_type, attribute_name_in, object_id_in; + raise EXCEPTION '-20000: No table name specified for storage specific static attribute %::% object_id % in acs_object.get_attribute_storage.',v_object_type, attribute_name_in, object_id_in; end if; end if; @@ -1080,124 +1242,148 @@ where object_type = v_object_type and table_name = v_table_name; if NOT FOUND then - raise EXCEPTION ''-20000: No data found for attribute %::% object_id % in acs_object.get_attribute_storage'', v_object_type, attribute_name_in, object_id_in; + raise EXCEPTION '-20000: No data found for attribute %::% object_id % in acs_object.get_attribute_storage', v_object_type, attribute_name_in, object_id_in; end if; end if; - if v_column is null or v_column = '''' then + if v_column is null or v_column = '' then - if v_storage = ''generic'' then - v_column := ''attr_value''; + if v_storage = 'generic' then + v_column := 'attr_value'; else v_column := v_attr_name; end if; end if; - if v_key_sql is null or v_key_sql = '''' then - if v_static = ''f'' then - v_key_sql := v_id_column || '' = '' || object_id_in ; + if v_key_sql is null or v_key_sql = '' then + if v_static = 'f' then + v_key_sql := v_id_column || ' = ' || object_id_in ; else - v_key_sql := v_id_column || '' = '''''' || v_object_type || ''''''''; + v_key_sql := v_id_column || ' = ''' || v_object_type || ''''; end if; end if; - return v_column || '','' || v_table_name || '','' || v_key_sql; + return v_column || ',' || v_table_name || ',' || v_key_sql; -end;' language 'plpgsql' stable; +END; +$$ LANGUAGE plpgsql stable; select define_function_args('acs_object__get_attr_storage_column','v_vals'); -create or replace function acs_object__get_attr_storage_column(text) -returns text as ' -declare - v_vals alias for $1; + + +-- +-- procedure acs_object__get_attr_storage_column/1 +-- +CREATE OR REPLACE FUNCTION acs_object__get_attr_storage_column( + v_vals text +) RETURNS text AS $$ +DECLARE v_idx integer; -begin - v_idx := strpos(v_vals,'',''); +BEGIN + v_idx := strpos(v_vals,','); if v_idx = 0 or v_vals is null then - raise exception ''invalid storage format: acs_object.get_attr_storage_column %'',v_vals; + raise exception 'invalid storage format: acs_object.get_attr_storage_column %',v_vals; end if; return substr(v_vals,1,v_idx - 1); -end;' language 'plpgsql' immutable; +END; +$$ LANGUAGE plpgsql immutable; select define_function_args('acs_object__get_attr_storage_table','v_vals'); -create or replace function acs_object__get_attr_storage_table(text) -returns text as ' -declare - v_vals alias for $1; + + +-- +-- procedure acs_object__get_attr_storage_table/1 +-- +CREATE OR REPLACE FUNCTION acs_object__get_attr_storage_table( + v_vals text +) RETURNS text AS $$ +DECLARE v_idx integer; v_tmp varchar; -begin - v_idx := strpos(v_vals,'',''); +BEGIN + v_idx := strpos(v_vals,','); if v_idx = 0 or v_vals is null then - raise exception ''invalid storage format: acs_object.get_attr_storage_table %'',v_vals; + raise exception 'invalid storage format: acs_object.get_attr_storage_table %',v_vals; end if; v_tmp := substr(v_vals,v_idx + 1); - v_idx := strpos(v_tmp,'',''); + v_idx := strpos(v_tmp,','); if v_idx = 0 then - raise exception ''invalid storage format: acs_object.get_attr_storage_table %'',v_vals; + raise exception 'invalid storage format: acs_object.get_attr_storage_table %',v_vals; end if; return substr(v_tmp,1,v_idx - 1); -end;' language 'plpgsql' immutable; +END; +$$ LANGUAGE plpgsql immutable; select define_function_args('acs_object__get_attr_storage_sql','v_vals'); -create or replace function acs_object__get_attr_storage_sql(text) -returns text as ' -declare - v_vals alias for $1; + + +-- +-- procedure acs_object__get_attr_storage_sql/1 +-- +CREATE OR REPLACE FUNCTION acs_object__get_attr_storage_sql( + v_vals text +) RETURNS text AS $$ +DECLARE v_idx integer; v_tmp varchar; -begin - v_idx := strpos(v_vals, '',''); +BEGIN + v_idx := strpos(v_vals, ','); if v_idx = 0 or v_vals is null then - raise exception ''invalid storage format: acs_object.get_attr_storage_sql %'',v_vals; + raise exception 'invalid storage format: acs_object.get_attr_storage_sql %',v_vals; end if; v_tmp := substr(v_vals, v_idx + 1); - v_idx := strpos(v_tmp, '',''); + v_idx := strpos(v_tmp, ','); if v_idx = 0 then - raise exception ''invalid storage format: acs_object.get_attr_storage_sql %'',v_vals; + raise exception 'invalid storage format: acs_object.get_attr_storage_sql %',v_vals; end if; return substr(v_tmp, v_idx + 1); -end;' language 'plpgsql' immutable; +END; +$$ LANGUAGE plpgsql immutable; -- function get_attribute select define_function_args('acs_object__get_attribute','object_id_in,attribute_name_in'); -create or replace function acs_object__get_attribute (integer,varchar) -returns text as ' -declare - object_id_in alias for $1; - attribute_name_in alias for $2; + + +-- +-- procedure acs_object__get_attribute/2 +-- +CREATE OR REPLACE FUNCTION acs_object__get_attribute( + object_id_in integer, + attribute_name_in varchar +) RETURNS text AS $$ +DECLARE v_table_name varchar(200); v_column varchar(200); v_key_sql text; v_return text; v_storage text; v_rec record; -begin +BEGIN v_storage := acs_object__get_attribute_storage(object_id_in, attribute_name_in); v_column := acs_object__get_attr_storage_column(v_storage); v_table_name := acs_object__get_attr_storage_table(v_storage); v_key_sql := acs_object__get_attr_storage_sql(v_storage); - for v_rec in execute ''select '' || quote_ident(v_column) || ''::text as column_return from '' || quote_ident(v_table_name) || '' where '' || v_key_sql + for v_rec in execute 'select ' || quote_ident(v_column) || '::text as column_return from ' || quote_ident(v_table_name) || ' where ' || v_key_sql LOOP v_return := v_rec.column_return; exit; @@ -1208,28 +1394,34 @@ return v_return; -end;' language 'plpgsql' stable; +END; +$$ LANGUAGE plpgsql stable; -- procedure set_attribute select define_function_args('acs_object__set_attribute','object_id_in,attribute_name_in,value_in'); -create or replace function acs_object__set_attribute (integer,varchar,varchar) -returns integer as ' -declare - object_id_in alias for $1; - attribute_name_in alias for $2; - value_in alias for $3; + + +-- +-- procedure acs_object__set_attribute/3 +-- +CREATE OR REPLACE FUNCTION acs_object__set_attribute( + object_id_in integer, + attribute_name_in varchar, + value_in varchar +) RETURNS integer AS $$ +DECLARE v_table_name varchar; v_column varchar; v_key_sql text; v_return text; v_storage text; -begin +BEGIN if value_in is null then -- this will fail more cryptically in the execute so catch now. - raise exception ''acs_object__set_attribute: attempt to set % to null for object_id %'',attribute_name_in, object_id_in; + raise exception 'acs_object__set_attribute: attempt to set % to null for object_id %',attribute_name_in, object_id_in; end if; v_storage := acs_object__get_attribute_storage(object_id_in, attribute_name_in); @@ -1238,28 +1430,34 @@ v_table_name := acs_object__get_attr_storage_table(v_storage); v_key_sql := acs_object__get_attr_storage_sql(v_storage); - execute ''update '' || v_table_name || '' set '' || quote_ident(v_column) || '' = '' || quote_literal(value_in) || '' where '' || v_key_sql; + execute 'update ' || v_table_name || ' set ' || quote_ident(v_column) || ' = ' || quote_literal(value_in) || ' where ' || v_key_sql; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function check_context_index select define_function_args('acs_object__check_context_index','check_context_index__object_id,check_context_index__ancestor_id,check_context_index__n_generations'); -create or replace function acs_object__check_context_index (integer,integer,integer) -returns boolean as ' -declare - check_context_index__object_id alias for $1; - check_context_index__ancestor_id alias for $2; - check_context_index__n_generations alias for $3; + + +-- +-- procedure acs_object__check_context_index/3 +-- +CREATE OR REPLACE FUNCTION acs_object__check_context_index( + check_context_index__object_id integer, + check_context_index__ancestor_id integer, + check_context_index__n_generations integer +) RETURNS boolean AS $$ +DECLARE n_rows integer; n_gens integer; -begin +BEGIN -- Verify that this row exists in the index. if check_context_index__object_id is null or check_context_index__ancestor_id is null then - raise exception ''object_id or ancestor_id is null in acs_object__check_context_index''; + raise exception 'object_id or ancestor_id is null in acs_object__check_context_index'; end if; select case when count(*) = 0 then 0 else 1 end into n_rows from acs_object_context_index @@ -1274,57 +1472,66 @@ and ancestor_id = check_context_index__ancestor_id; if n_gens != check_context_index__n_generations then - PERFORM acs_log__error(''acs_object.check_representation'', - ''Ancestor '' || - check_context_index__ancestor_id || '' of object '' || + PERFORM acs_log__error('acs_object.check_representation', + 'Ancestor ' || + check_context_index__ancestor_id || ' of object ' || check_context_index__object_id || - '' reports being generation '' || n_gens || - '' when it is actually generation '' || + ' reports being generation ' || n_gens || + ' when it is actually generation ' || check_context_index__n_generations || - ''.''); - return ''f''; + '.'); + return 'f'; else - return ''t''; + return 't'; end if; else - PERFORM acs_log__error(''acs_object.check_representation'', - ''Ancestor '' || + PERFORM acs_log__error('acs_object.check_representation', + 'Ancestor ' || check_context_index__ancestor_id || - '' of object '' || check_context_index__object_id - || '' is missing an entry in acs_object_context_index.''); - return ''f''; + ' of object ' || check_context_index__object_id + || ' is missing an entry in acs_object_context_index.'); + return 'f'; end if; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function check_object_ancestors -create function acs_object__check_object_ancestors (integer,integer,integer) -returns boolean as ' -declare - check_object_ancestors__object_id alias for $1; - check_object_ancestors__ancestor_id alias for $2; - check_object_ancestors__n_generations alias for $3; + + +-- added +select define_function_args('acs_object__check_object_ancestors','object_id,ancestor_id,n_generations'); + +-- +-- procedure acs_object__check_object_ancestors/3 +-- +CREATE OR REPLACE FUNCTION acs_object__check_object_ancestors( + check_object_ancestors__object_id integer, + check_object_ancestors__ancestor_id integer, + check_object_ancestors__n_generations integer +) RETURNS boolean AS $$ +DECLARE check_object_ancestors__context_id acs_objects.context_id%TYPE; check_object_ancestors__security_inherit_p acs_objects.security_inherit_p%TYPE; n_rows integer; n_gens integer; result boolean; -begin +BEGIN -- OBJECT_ID is the object we are verifying -- ANCESTOR_ID is the current ancestor we are tracking -- N_GENERATIONS is how far ancestor_id is from object_id -- Note that this function is only supposed to verify that the - -- index contains each ancestor for OBJECT_ID. It doesn''''t - -- guarantee that there aren''''t extraneous rows or that - -- OBJECT_ID''''s children are contained in the index. That is + -- index contains each ancestor for OBJECT_ID. It doesn''t + -- guarantee that there aren''t extraneous rows or that + -- OBJECT_ID''s children are contained in the index. That is -- verified by seperate functions. - result := ''t''; + result := 't'; -- Grab the context and security_inherit_p flag of the current - -- ancestor''''s parent. + -- ancestor''s parent. select context_id, security_inherit_p into check_object_ancestors__context_id, check_object_ancestors__security_inherit_p @@ -1333,100 +1540,115 @@ if check_object_ancestors__ancestor_id = 0 then if check_object_ancestors__context_id is null then - result := ''t''; + result := 't'; else - -- This can be a constraint, can''''t it? - PERFORM acs_log__error(''acs_object.check_representation'', - ''Object 0 doesn''''t have a null context_id''); - result := ''f''; + -- This can be a constraint, can''t it? + PERFORM acs_log__error('acs_object.check_representation', + 'Object 0 doesn''t have a null context_id'); + result := 'f'; end if; else if check_object_ancestors__context_id is null or - check_object_ancestors__security_inherit_p = ''f'' + check_object_ancestors__security_inherit_p = 'f' THEN check_object_ancestors__context_id := 0; end if; if acs_object__check_context_index(check_object_ancestors__object_id, check_object_ancestors__ancestor_id, - check_object_ancestors__n_generations) = ''f'' then - result := ''f''; + check_object_ancestors__n_generations) = 'f' then + result := 'f'; end if; if acs_object__check_object_ancestors(check_object_ancestors__object_id, check_object_ancestors__context_id, - check_object_ancestors__n_generations + 1) = ''f'' then - result := ''f''; + check_object_ancestors__n_generations + 1) = 'f' then + result := 'f'; end if; end if; return result; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function check_object_descendants -create function acs_object__check_object_descendants (integer,integer,integer) -returns boolean as ' -declare - object_id alias for $1; - descendant_id alias for $2; - n_generations alias for $3; + + +-- added +select define_function_args('acs_object__check_object_descendants','object_id,descendant_id,n_generations'); + +-- +-- procedure acs_object__check_object_descendants/3 +-- +CREATE OR REPLACE FUNCTION acs_object__check_object_descendants( + object_id integer, + descendant_id integer, + n_generations integer +) RETURNS boolean AS $$ +DECLARE result boolean; obj record; -begin +BEGIN -- OBJECT_ID is the object we are verifying. -- DESCENDANT_ID is the current descendant we are tracking. -- N_GENERATIONS is how far the current DESCENDANT_ID is from -- OBJECT_ID. -- This function will verfy that each actualy descendant of -- OBJECT_ID has a row in the index table. It does not check that - -- there aren''t extraneous rows or that the ancestors of OBJECT_ID + -- there aren't extraneous rows or that the ancestors of OBJECT_ID -- are maintained correctly. - result := ''t''; + result := 't'; -- First verify that OBJECT_ID and DESCENDANT_ID are actually in -- the index. - if acs_object__check_context_index(descendant_id, object_id, n_generations) = ''f'' then - result := ''f''; + if acs_object__check_context_index(descendant_id, object_id, n_generations) = 'f' then + result := 'f'; end if; -- For every child that reports inheriting from OBJECT_ID we need to call -- ourselves recursively. for obj in select * from acs_objects where context_id = descendant_id - and security_inherit_p = ''t'' loop + and security_inherit_p = 't' loop if acs_object__check_object_descendants(object_id, obj.object_id, - n_generations + 1) = ''f'' then - result := ''f''; + n_generations + 1) = 'f' then + result := 'f'; end if; end loop; return result; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function check_path select define_function_args('acs_object__check_path','check_path__object_id,check_path__ancestor_id'); -create or replace function acs_object__check_path (integer,integer) -returns boolean as ' -declare - check_path__object_id alias for $1; - check_path__ancestor_id alias for $2; + + +-- +-- procedure acs_object__check_path/2 +-- +CREATE OR REPLACE FUNCTION acs_object__check_path( + check_path__object_id integer, + check_path__ancestor_id integer +) RETURNS boolean AS $$ +DECLARE check_path__context_id acs_objects.context_id%TYPE; check_path__security_inherit_p acs_objects.security_inherit_p%TYPE; -begin +BEGIN if check_path__object_id is null or check_path__ancestor_id then - raise exception ''acs_object__check_path called with null object_id or ancestor_id''; + raise exception 'acs_object__check_path called with null object_id or ancestor_id'; end if; if check_path__object_id = check_path__ancestor_id then - return ''t''; + return 't'; end if; select context_id, security_inherit_p @@ -1438,49 +1660,55 @@ -- should we not? if check_path__object_id = 0 and check_path__context_id is null then - return ''f''; + return 'f'; end if; - if check_path__context_id is null or check_path__security_inherit_p = ''f'' + if check_path__context_id is null or check_path__security_inherit_p = 'f' then check_path__context_id := 0; end if; return acs_object__check_path(check_path__context_id, check_path__ancestor_id); -end;' language 'plpgsql' stable; +END; +$$ LANGUAGE plpgsql stable; -- function check_representation select define_function_args('acs_object__check_representation','check_representation__object_id'); -create or replace function acs_object__check_representation (integer) -returns boolean as ' -declare - check_representation__object_id alias for $1; + + +-- +-- procedure acs_object__check_representation/1 +-- +CREATE OR REPLACE FUNCTION acs_object__check_representation( + check_representation__object_id integer +) RETURNS boolean AS $$ +DECLARE result boolean; check_representation__object_type acs_objects.object_type%TYPE; n_rows integer; v_rec record; row record; -begin +BEGIN if check_representation__object_id is null then - raise exception ''acs_object__check_representation called for null object_id''; + raise exception 'acs_object__check_representation called for null object_id'; end if; - result := ''t''; - PERFORM acs_log__notice(''acs_object.check_representation'', - ''Running acs_object.check_representation on object_id = '' - || check_representation__object_id || ''.''); + result := 't'; + PERFORM acs_log__notice('acs_object.check_representation', + 'Running acs_object.check_representation on object_id = ' + || check_representation__object_id || '.'); select object_type into check_representation__object_type from acs_objects where object_id = check_representation__object_id; - PERFORM acs_log__notice(''acs_object.check_representation'', - ''OBJECT STORAGE INTEGRITY TEST''); + PERFORM acs_log__notice('acs_object.check_representation', + 'OBJECT STORAGE INTEGRITY TEST'); for v_rec in select t.object_type, t.table_name, t.id_column from acs_object_type_supertype_map m, acs_object_types t @@ -1492,80 +1720,98 @@ where object_type = check_representation__object_type LOOP - for row in execute ''select case when count(*) = 0 then 0 else 1 end as n_rows from '' || quote_ident(v_rec.table_name) || '' where '' || quote_ident(v_rec.id_column) || '' = '' || check_representation__object_id + for row in execute 'select case when count(*) = 0 then 0 else 1 end as n_rows from ' || quote_ident(v_rec.table_name) || ' where ' || quote_ident(v_rec.id_column) || ' = ' || check_representation__object_id LOOP n_rows := row.n_rows; exit; end LOOP; if n_rows = 0 then - result := ''f''; - PERFORM acs_log__error(''acs_object.check_representation'', - ''Table '' || v_rec.table_name || - '' (primary storage for '' || + result := 'f'; + PERFORM acs_log__error('acs_object.check_representation', + 'Table ' || v_rec.table_name || + ' (primary storage for ' || v_rec.object_type || - '') doesn''''t have a row for object '' || - check_representation__object_id || '' of type '' || - check_representation__object_type || ''.''); + ') doesn''t have a row for object ' || + check_representation__object_id || ' of type ' || + check_representation__object_type || '.'); end if; end loop; - PERFORM acs_log__notice(''acs_object.check_representation'', - ''OBJECT CONTEXT INTEGRITY TEST''); + PERFORM acs_log__notice('acs_object.check_representation', + 'OBJECT CONTEXT INTEGRITY TEST'); if acs_object__check_object_ancestors(check_representation__object_id, - check_representation__object_id, 0) = ''f'' then - result := ''f''; + check_representation__object_id, 0) = 'f' then + result := 'f'; end if; if acs_object__check_object_descendants(check_representation__object_id, - check_representation__object_id, 0) = ''f'' then - result := ''f''; + check_representation__object_id, 0) = 'f' then + result := 'f'; end if; for row in select object_id, ancestor_id, n_generations from acs_object_context_index where object_id = check_representation__object_id or ancestor_id = check_representation__object_id LOOP - if acs_object__check_path(row.object_id, row.ancestor_id) = ''f'' then - PERFORM acs_log__error(''acs_object.check_representation'', - ''acs_object_context_index contains an extraneous row: '' - || ''object_id = '' || row.object_id || - '', ancestor_id = '' || row.ancestor_id || - '', n_generations = '' || row.n_generations || ''.''); - result := ''f''; + if acs_object__check_path(row.object_id, row.ancestor_id) = 'f' then + PERFORM acs_log__error('acs_object.check_representation', + 'acs_object_context_index contains an extraneous row: ' + || 'object_id = ' || row.object_id || + ', ancestor_id = ' || row.ancestor_id || + ', n_generations = ' || row.n_generations || '.'); + result := 'f'; end if; end loop; - PERFORM acs_log__notice(''acs_object.check_representation'', - ''Done running acs_object.check_representation '' || - ''on object_id = '' || check_representation__object_id || ''.''); + PERFORM acs_log__notice('acs_object.check_representation', + 'Done running acs_object.check_representation ' || + 'on object_id = ' || check_representation__object_id || '.'); return result; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create function acs_object__update_last_modified (integer, integer, varchar) -returns integer as ' -declare - acs_object__update_last_modified__object_id alias for $1; - acs_object__update_last_modified__modifying_user alias for $2; - acs_object__update_last_modified__modifying_ip alias for $3; -begin + + +-- added + +-- +-- procedure acs_object__update_last_modified/3 +-- +CREATE OR REPLACE FUNCTION acs_object__update_last_modified( + acs_object__update_last_modified__object_id integer, + acs_object__update_last_modified__modifying_user integer, + acs_object__update_last_modified__modifying_ip varchar +) RETURNS integer AS $$ +DECLARE +BEGIN return acs_object__update_last_modified(acs_object__update_last_modified__object_id, acs_object__update_last_modified__modifying_user, acs_object__update_last_modified__modifying_ip, now()); -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create function acs_object__update_last_modified (integer, integer, varchar, timestamptz) -returns integer as ' -declare - acs_object__update_last_modified__object_id alias for $1; - acs_object__update_last_modified__modifying_user alias for $2; - acs_object__update_last_modified__modifying_ip alias for $3; - acs_object__update_last_modified__last_modified alias for $4; -- default now() + + +-- added +select define_function_args('acs_object__update_last_modified','update_last_modified__object_id,update_last_modified__modifying_user,update_last_modified__modifying_ip,update_last_modified__last_modified;now()'); + +-- +-- procedure acs_object__update_last_modified/4 +-- +CREATE OR REPLACE FUNCTION acs_object__update_last_modified( + acs_object__update_last_modified__object_id integer, + acs_object__update_last_modified__modifying_user integer, + acs_object__update_last_modified__modifying_ip varchar, + acs_object__update_last_modified__last_modified timestamptz -- default now() + +) RETURNS integer AS $$ +DECLARE v_parent_id integer; v_last_modified timestamptz; -begin +BEGIN if acs_object__update_last_modified__last_modified is null then v_last_modified := now(); else @@ -1588,7 +1834,8 @@ end if; return acs_object__update_last_modified__object_id; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- show errors Index: openacs-4/packages/acs-kernel/sql/postgresql/acs-permissions-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/postgresql/acs-permissions-create.sql,v diff -u -r1.34 -r1.35 --- openacs-4/packages/acs-kernel/sql/postgresql/acs-permissions-create.sql 10 Mar 2010 00:44:03 -0000 1.34 +++ openacs-4/packages/acs-kernel/sql/postgresql/acs-permissions-create.sql 7 Jul 2011 10:46:02 -0000 1.35 @@ -118,18 +118,25 @@ -- This would be better, since the same query could be used for both oracle -- and postgresql. -create or replace function acs_priv_hier_ins_del_tr () returns trigger as ' -declare + + +-- +-- procedure acs_priv_hier_ins_del_tr/0 +-- +CREATE OR REPLACE FUNCTION acs_priv_hier_ins_del_tr( + +) RETURNS trigger AS $$ +DECLARE new_value integer; new_key varbit default null; v_rec record; deleted_p boolean; -begin +BEGIN -- if more than one node was deleted the second trigger call -- will error out. This check avoids that problem. - if TG_OP = ''DELETE'' then + if TG_OP = 'DELETE' then select count(*) = 0 into deleted_p from acs_privilege_hierarchy_index where old.privilege = privilege @@ -184,35 +191,45 @@ return new; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; create trigger acs_priv_hier_ins_del_tr after insert or delete on acs_privilege_hierarchy for each row execute procedure acs_priv_hier_ins_del_tr (); -create or replace function acs_priv_del_tr () returns trigger as ' -begin +CREATE OR REPLACE FUNCTION acs_priv_del_tr () RETURNS trigger AS $$ +BEGIN delete from acs_privilege_descendant_map where privilege = old.privilege; return old; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; create trigger acs_priv_del_tr before delete on acs_privileges for each row execute procedure acs_priv_del_tr (); -create function priv_recurse_subtree(varbit, varchar) -returns integer as ' -declare - nkey alias for $1; - child_priv alias for $2; + + +-- added +select define_function_args('priv_recurse_subtree','nkey,child_priv'); + +-- +-- procedure priv_recurse_subtree/2 +-- +CREATE OR REPLACE FUNCTION priv_recurse_subtree( + nkey varbit, + child_priv varchar +) RETURNS integer AS $$ +DECLARE new_value integer; v_rec record; new_key varbit; -begin +BEGIN -- now iterate over all of the children of the -- previous node. @@ -257,7 +274,8 @@ return null; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; comment on table acs_privileges is ' Privileges share a global namespace. This is to avoid a @@ -271,13 +289,22 @@ privilege is a superset of the bar privilege. '; -create function acs_privilege__create_privilege (varchar,varchar,varchar) -returns integer as ' -declare - create_privilege__privilege alias for $1; - create_privilege__pretty_name alias for $2; -- default null - create_privilege__pretty_plural alias for $3; -- default null -begin + + +-- added +select define_function_args('acs_privilege__create_privilege','privilege,pretty_name;null,pretty_plural;null'); + +-- +-- procedure acs_privilege__create_privilege/3 +-- +CREATE OR REPLACE FUNCTION acs_privilege__create_privilege( + create_privilege__privilege varchar, + create_privilege__pretty_name varchar, -- default null + create_privilege__pretty_plural varchar -- default null + +) RETURNS integer AS $$ +DECLARE +BEGIN insert into acs_privileges (privilege, pretty_name, pretty_plural) values @@ -286,54 +313,88 @@ create_privilege__pretty_plural); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create function acs_privilege__create_privilege (varchar) -returns integer as ' -declare - create_privilege__privilege alias for $1; -begin + + +-- +-- procedure acs_privilege__create_privilege/1 +-- +CREATE OR REPLACE FUNCTION acs_privilege__create_privilege( + create_privilege__privilege varchar +) RETURNS integer AS $$ +DECLARE +BEGIN return acs_privilege__create_privilege(create_privilege__privilege, null, null); -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create function acs_privilege__drop_privilege (varchar) -returns integer as ' -declare - drop_privilege__privilege alias for $1; -begin + + +-- added +select define_function_args('acs_privilege__drop_privilege','privilege'); + +-- +-- procedure acs_privilege__drop_privilege/1 +-- +CREATE OR REPLACE FUNCTION acs_privilege__drop_privilege( + drop_privilege__privilege varchar +) RETURNS integer AS $$ +DECLARE +BEGIN delete from acs_privileges where privilege = drop_privilege__privilege; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create function acs_privilege__add_child (varchar,varchar) -returns integer as ' -declare - add_child__privilege alias for $1; - add_child__child_privilege alias for $2; -begin + + +-- added +select define_function_args('acs_privilege__add_child','privilege,child_privilege'); + +-- +-- procedure acs_privilege__add_child/2 +-- +CREATE OR REPLACE FUNCTION acs_privilege__add_child( + add_child__privilege varchar, + add_child__child_privilege varchar +) RETURNS integer AS $$ +DECLARE +BEGIN insert into acs_privilege_hierarchy (privilege, child_privilege) values (add_child__privilege, add_child__child_privilege); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create function acs_privilege__remove_child (varchar,varchar) -returns integer as ' -declare - remove_child__privilege alias for $1; - remove_child__child_privilege alias for $2; -begin + + +-- added +select define_function_args('acs_privilege__remove_child','privilege,child_privilege'); + +-- +-- procedure acs_privilege__remove_child/2 +-- +CREATE OR REPLACE FUNCTION acs_privilege__remove_child( + remove_child__privilege varchar, + remove_child__child_privilege varchar +) RETURNS integer AS $$ +DECLARE +BEGIN delete from acs_privilege_hierarchy where privilege = remove_child__privilege and child_privilege = remove_child__child_privilege; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; ------------------------------------ @@ -418,24 +479,33 @@ lck integer ); -create function acs_permissions_lock_tr () returns trigger as ' -begin - raise EXCEPTION ''FOR LOCKING ONLY, NO DML STATEMENTS ALLOWED''; +CREATE OR REPLACE FUNCTION acs_permissions_lock_tr () RETURNS trigger AS $$ +BEGIN + raise EXCEPTION 'FOR LOCKING ONLY, NO DML STATEMENTS ALLOWED'; return null; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; create trigger acs_permissions_lock_tr before insert or update or delete on acs_permissions_lock for each row execute procedure acs_permissions_lock_tr(); -create function acs_permission__grant_permission (integer, integer, varchar) -returns integer as ' -declare - grant_permission__object_id alias for $1; - grant_permission__grantee_id alias for $2; - grant_permission__privilege alias for $3; + + +-- added +select define_function_args('acs_permission__grant_permission','object_id,grantee_id,privilege'); + +-- +-- procedure acs_permission__grant_permission/3 +-- +CREATE OR REPLACE FUNCTION acs_permission__grant_permission( + grant_permission__object_id integer, + grant_permission__grantee_id integer, + grant_permission__privilege varchar +) RETURNS integer AS $$ +DECLARE exists_p boolean; -begin +BEGIN lock table acs_permissions_lock; select count(*) > 0 into exists_p @@ -459,17 +529,26 @@ -- return; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure revoke_permission -create or replace function acs_permission__revoke_permission (integer, integer, varchar) -returns integer as ' -declare - revoke_permission__object_id alias for $1; - revoke_permission__grantee_id alias for $2; - revoke_permission__privilege alias for $3; -begin + + +-- added +select define_function_args('acs_permission__revoke_permission','object_id,grantee_id,privilege'); + +-- +-- procedure acs_permission__revoke_permission/3 +-- +CREATE OR REPLACE FUNCTION acs_permission__revoke_permission( + revoke_permission__object_id integer, + revoke_permission__grantee_id integer, + revoke_permission__privilege varchar +) RETURNS integer AS $$ +DECLARE +BEGIN lock table acs_permissions_lock; delete from acs_permissions @@ -478,18 +557,27 @@ and privilege = revoke_permission__privilege; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- Really speedy version of permission_p written by Don Baccus -create or replace function acs_permission__permission_p (integer,integer,varchar) -returns boolean as ' -declare - permission_p__object_id alias for $1; - permission_p__party_id alias for $2; - permission_p__privilege alias for $3; + + +-- added +select define_function_args('acs_permission__permission_p','object_id,party_id,privilege'); + +-- +-- procedure acs_permission__permission_p/3 +-- +CREATE OR REPLACE FUNCTION acs_permission__permission_p( + permission_p__object_id integer, + permission_p__party_id integer, + permission_p__privilege varchar +) RETURNS boolean AS $$ +DECLARE exists_p boolean; -begin +BEGIN return exists (select 1 from acs_permissions p, party_approved_member_map m, acs_object_context_index c, acs_privilege_descendant_map h @@ -499,4 +587,5 @@ and m.member_id = permission_p__party_id and p.privilege = h.privilege and p.grantee_id = m.party_id); -end;' language 'plpgsql' stable; +END; +$$ LANGUAGE plpgsql stable; Index: openacs-4/packages/acs-kernel/sql/postgresql/acs-relationships-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/postgresql/acs-relationships-create.sql,v diff -u -r1.31 -r1.32 --- openacs-4/packages/acs-kernel/sql/postgresql/acs-relationships-create.sql 10 Mar 2010 00:44:03 -0000 1.31 +++ openacs-4/packages/acs-kernel/sql/postgresql/acs-relationships-create.sql 7 Jul 2011 10:46:02 -0000 1.32 @@ -81,100 +81,152 @@ '; -create function acs_rel_type__create_role (varchar,varchar,varchar) -returns integer as ' -declare - create_role__role alias for $1; - create_role__pretty_name alias for $2; -- default null - create_role__pretty_plural alias for $3; -- default null -begin + + +-- added +select define_function_args('acs_rel_type__create_role','role,pretty_name;null,pretty_plural;null'); + +-- +-- procedure acs_rel_type__create_role/3 +-- +CREATE OR REPLACE FUNCTION acs_rel_type__create_role( + create_role__role varchar, + create_role__pretty_name varchar, -- default null + create_role__pretty_plural varchar -- default null + +) RETURNS integer AS $$ +DECLARE +BEGIN insert into acs_rel_roles (role, pretty_name, pretty_plural) values (create_role__role, coalesce(create_role__pretty_name,create_role__role), coalesce(create_role__pretty_plural,create_role__role)); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create function acs_rel_type__create_role (varchar) -returns integer as ' -declare - create_role__role alias for $1; -begin + + +-- +-- procedure acs_rel_type__create_role/1 +-- +CREATE OR REPLACE FUNCTION acs_rel_type__create_role( + create_role__role varchar +) RETURNS integer AS $$ +DECLARE +BEGIN perform acs_rel_type__create_role(create_role__role, NULL, NULL); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure drop_role -create function acs_rel_type__drop_role (varchar) -returns integer as ' -declare - drop_role__role alias for $1; -begin + + +-- added +select define_function_args('acs_rel_type__drop_role','role'); + +-- +-- procedure acs_rel_type__drop_role/1 +-- +CREATE OR REPLACE FUNCTION acs_rel_type__drop_role( + drop_role__role varchar +) RETURNS integer AS $$ +DECLARE +BEGIN delete from acs_rel_roles where role = drop_role__role; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function role_pretty_name -create or replace function acs_rel_type__role_pretty_name (varchar) -returns varchar as ' -declare - role_pretty_name__role alias for $1; + + +-- added +select define_function_args('acs_rel_type__role_pretty_name','role'); + +-- +-- procedure acs_rel_type__role_pretty_name/1 +-- +CREATE OR REPLACE FUNCTION acs_rel_type__role_pretty_name( + role_pretty_name__role varchar +) RETURNS varchar AS $$ +DECLARE v_pretty_name acs_rel_roles.pretty_name%TYPE; -begin +BEGIN select r.pretty_name into v_pretty_name from acs_rel_roles r where r.role = role_pretty_name__role; return v_pretty_name; -end;' language 'plpgsql' stable strict; +END; +$$ LANGUAGE plpgsql stable strict; -- function role_pretty_plural -create function acs_rel_type__role_pretty_plural (varchar) -returns varchar as ' -declare - role_pretty_plural__role alias for $1; + + +-- added +select define_function_args('acs_rel_type__role_pretty_plural','role'); + +-- +-- procedure acs_rel_type__role_pretty_plural/1 +-- +CREATE OR REPLACE FUNCTION acs_rel_type__role_pretty_plural( + role_pretty_plural__role varchar +) RETURNS varchar AS $$ +DECLARE v_pretty_plural acs_rel_roles.pretty_plural%TYPE; -begin +BEGIN select r.pretty_plural into v_pretty_plural from acs_rel_roles r where r.role = role_pretty_plural__role; return v_pretty_plural; -end;' language 'plpgsql' stable strict; +END; +$$ LANGUAGE plpgsql stable strict; -- procedure create_type -create function acs_rel_type__create_type (varchar,varchar,varchar,varchar,varchar,varchar,varchar,varchar,varchar,integer,integer,varchar,varchar,integer,integer) -returns integer as ' -declare - create_type__rel_type alias for $1; - create_type__pretty_name alias for $2; - create_type__pretty_plural alias for $3; - create_type__supertype alias for $4; -- default ''relationship'' - create_type__table_name alias for $5; - create_type__id_column alias for $6; - create_type__package_name alias for $7; - create_type__object_type_one alias for $8; - create_type__role_one alias for $9; -- default null - create_type__min_n_rels_one alias for $10; - create_type__max_n_rels_one alias for $11; - create_type__object_type_two alias for $12; - create_type__role_two alias for $13; -- default null - create_type__min_n_rels_two alias for $14; - create_type__max_n_rels_two alias for $15; + +-- added +select define_function_args('acs_rel_type__create_type','rel_type,pretty_name,pretty_plural,supertype;relationship,table_name,id_column,package_name,object_type_one,role_one;null,min_n_rels_one,max_n_rels_one,object_type_two,role_two;null,min_n_rels_two,max_n_rels_two'); + +-- +-- procedure acs_rel_type__create_type/15 +-- +CREATE OR REPLACE FUNCTION acs_rel_type__create_type( + create_type__rel_type varchar, + create_type__pretty_name varchar, + create_type__pretty_plural varchar, + create_type__supertype varchar, -- default 'relationship' + create_type__table_name varchar, + create_type__id_column varchar, + create_type__package_name varchar, + create_type__object_type_one varchar, + create_type__role_one varchar, -- default null + create_type__min_n_rels_one integer, + create_type__max_n_rels_one integer, + create_type__object_type_two varchar, + create_type__role_two varchar, -- default null + create_type__min_n_rels_two integer, + create_type__max_n_rels_two integer + +) RETURNS integer AS $$ +DECLARE + type_extension_table acs_object_types.type_extension_table%TYPE default null; - abstract_p acs_object_types.abstract_p%TYPE default ''f''; + abstract_p acs_object_types.abstract_p%TYPE default 'f'; name_method acs_object_types.name_method%TYPE default null; -begin +BEGIN PERFORM acs_object_type__create_type( create_type__rel_type, create_type__pretty_name, @@ -202,34 +254,41 @@ create_type__min_n_rels_two, create_type__max_n_rels_two); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure create_type -create function acs_rel_type__create_type (varchar,varchar,varchar,varchar,varchar,varchar,varchar,varchar,varchar,integer,integer,varchar,integer,integer) -returns integer as ' -declare - create_type__rel_type alias for $1; - create_type__pretty_name alias for $2; - create_type__pretty_plural alias for $3; - create_type__supertype alias for $4; -- default ''relationship'' - create_type__table_name alias for $5; - create_type__id_column alias for $6; - create_type__package_name alias for $7; - create_type__type_extension_table alias for $8; -- default null - create_type__object_type_one alias for $9; - create_type__min_n_rels_one alias for $10; - create_type__max_n_rels_one alias for $11; - create_type__object_type_two alias for $12; - create_type__min_n_rels_two alias for $13; - create_type__max_n_rels_two alias for $14; - abstract_p acs_object_types.abstract_p%TYPE default ''f''; + +-- +-- procedure acs_rel_type__create_type/14 +-- +CREATE OR REPLACE FUNCTION acs_rel_type__create_type( + create_type__rel_type varchar, + create_type__pretty_name varchar, + create_type__pretty_plural varchar, + create_type__supertype varchar, -- default 'relationship' + create_type__table_name varchar, + create_type__id_column varchar, + create_type__package_name varchar, + create_type__type_extension_table varchar, -- default null + create_type__object_type_one varchar, + create_type__min_n_rels_one integer, + create_type__max_n_rels_one integer, + create_type__object_type_two varchar, + create_type__min_n_rels_two integer, + create_type__max_n_rels_two integer + +) RETURNS integer AS $$ +DECLARE + + abstract_p acs_object_types.abstract_p%TYPE default 'f'; name_method acs_object_types.name_method%TYPE default null; create_type__role_one acs_rel_types.role_one%TYPE default null; create_type__role_two acs_rel_types.role_two%TYPE default null; -begin +BEGIN PERFORM acs_object_type__create_type( create_type__rel_type, @@ -258,22 +317,32 @@ create_type__min_n_rels_two, create_type__max_n_rels_two); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure drop_type -create or replace function acs_rel_type__drop_type (varchar,boolean) -returns integer as ' -declare - drop_type__rel_type alias for $1; - drop_type__cascade_p alias for $2; -- default ''f'' + + +-- added +select define_function_args('acs_rel_type__drop_type','rel_type,cascade_p;f'); + +-- +-- procedure acs_rel_type__drop_type/2 +-- +CREATE OR REPLACE FUNCTION acs_rel_type__drop_type( + drop_type__rel_type varchar, + drop_type__cascade_p boolean -- default 'f' + +) RETURNS integer AS $$ +DECLARE v_cascade_p boolean; -begin +BEGIN -- XXX do cascade_p. -- JCD: cascade_p seems to be ignored in acs_o_type__drop_type anyway... if drop_type__cascade_p is null then - v_cascade_p := ''f''; + v_cascade_p := 'f'; else v_cascade_p := drop_type__cascade_p; end if; @@ -285,7 +354,8 @@ v_cascade_p); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; @@ -394,16 +464,23 @@ -- added by oumi@arsdigita.com - Jan 11, 2001 -create function acs_rels_in_tr () returns trigger as ' -declare + + +-- +-- procedure acs_rels_in_tr/0 +-- +CREATE OR REPLACE FUNCTION acs_rels_in_tr( + +) RETURNS trigger AS $$ +DECLARE dummy integer; target_object_type_one acs_object_types.object_type%TYPE; target_object_type_two acs_object_types.object_type%TYPE; actual_object_type_one acs_object_types.object_type%TYPE; actual_object_type_two acs_object_types.object_type%TYPE; -begin +BEGIN - -- DRB: The obvious rewrite to use Dan''s port of this to use tree_ancestor_keys kills + -- DRB: The obvious rewrite to use Dan's port of this to use tree_ancestor_keys kills -- Postgres!!! Argh!!! This is fast, to, so there ... -- Get all the object type info from the relationship. @@ -430,7 +507,7 @@ where root1.tree_sortkey = parents1.tree_sortkey and root2.tree_sortkey = parents2.tree_sortkey) then - raise EXCEPTION ''-20001: % violation: Invalid object types. Object % (%) must be of type % Object % (%) must be of type %'', new.rel_type, + raise EXCEPTION '-20001: % violation: Invalid object types. Object % (%) must be of type % Object % (%) must be of type %', new.rel_type, new.object_id_one, actual_object_type_one, target_object_type_one, @@ -442,7 +519,8 @@ return new; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; create trigger acs_rels_in_tr before insert or update on acs_rels for each row execute procedure acs_rels_in_tr (); @@ -474,28 +552,38 @@ -- create or replace package body acs_rel -- function new -select define_function_args('acs_rel__new','rel_id,rel_type,object_id_one,object_id_two,context_id,creation_user,creation_ip'); -create or replace function acs_rel__new (integer,varchar,integer,integer,integer,integer,varchar) -returns integer as ' -declare - new__rel_id alias for $1; -- default null - new__rel_type alias for $2; -- default ''relationship'' - new__object_id_one alias for $3; - new__object_id_two alias for $4; - context_id alias for $5; -- default null - creation_user alias for $6; -- default null - creation_ip alias for $7; -- default null + +-- old define_function_args('acs_rel__new','rel_id,rel_type,object_id_one,object_id_two,context_id,creation_user,creation_ip') +-- new +select define_function_args('acs_rel__new','rel_id;null,rel_type;relationship,object_id_one,object_id_two,context_id;null,creation_user;null,creation_ip;null'); + + + +-- +-- procedure acs_rel__new/7 +-- +CREATE OR REPLACE FUNCTION acs_rel__new( + new__rel_id integer, -- default null + new__rel_type varchar, -- default 'relationship' + new__object_id_one integer, + new__object_id_two integer, + context_id integer, -- default null + creation_user integer, -- default null + creation_ip varchar -- default null + +) RETURNS integer AS $$ +DECLARE v_rel_id acs_rels.rel_id%TYPE; -begin +BEGIN v_rel_id := acs_object__new ( new__rel_id, new__rel_type, now(), creation_user, creation_ip, context_id, - ''t'', - new__rel_type || '': '' || new__object_id_one || '' - '' || new__object_id_two, + 't', + new__rel_type || ': ' || new__object_id_one || ' - ' || new__object_id_two, null ); @@ -506,20 +594,27 @@ return v_rel_id; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure delete select define_function_args('acs_rel__delete','rel_id'); -create function acs_rel__delete (integer) -returns integer as ' -declare - rel_id alias for $1; -begin + + +-- +-- procedure acs_rel__delete/1 +-- +CREATE OR REPLACE FUNCTION acs_rel__delete( + rel_id integer +) RETURNS integer AS $$ +DECLARE +BEGIN PERFORM acs_object__delete(rel_id); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; ----------- -- VIEWS -- Index: openacs-4/packages/acs-kernel/sql/postgresql/apm-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/postgresql/apm-create.sql,v diff -u -r1.74 -r1.75 --- openacs-4/packages/acs-kernel/sql/postgresql/apm-create.sql 31 Oct 2010 00:15:01 -0000 1.74 +++ openacs-4/packages/acs-kernel/sql/postgresql/apm-create.sql 7 Jul 2011 10:46:02 -0000 1.75 @@ -95,25 +95,25 @@ request processor. '; -create or replace function inline_0 () -returns integer as ' -begin +CREATE OR REPLACE FUNCTION inline_0 () RETURNS integer AS $$ +BEGIN -- Create a new object type for packages. PERFORM acs_object_type__create_type ( - ''apm_package'', -- object_type - ''Package'', -- pretty_name - ''Packages'', -- pretty_plural - ''acs_object'', -- supertype - ''apm_packages'', -- table_name - ''package_id'', -- id_column - ''apm_package'', -- package_name - ''f'', -- abstract_p - ''apm_package_types'', -- type_extension_table - ''apm_package__name'' -- name_method + 'apm_package', -- object_type + 'Package', -- pretty_name + 'Packages', -- pretty_plural + 'acs_object', -- supertype + 'apm_packages', -- table_name + 'package_id', -- id_column + 'apm_package', -- package_name + 'f', -- abstract_p + 'apm_package_types', -- type_extension_table + 'apm_package__name' -- name_method ); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select inline_0 (); @@ -122,30 +122,37 @@ -- show errors -create or replace function inline_1 () -returns integer as ' -declare + + +-- +-- procedure inline_1/0 +-- +CREATE OR REPLACE FUNCTION inline_1( + +) RETURNS integer AS $$ +DECLARE attr_id acs_attributes.attribute_id%TYPE; -begin +BEGIN -- Register the meta-data for APM-packages attr_id := acs_attribute__create_attribute ( - ''apm_package'', - ''package_key'', - ''string'', - ''Package Key'', - ''Package Keys'', + 'apm_package', + 'package_key', + 'string', + 'Package Key', + 'Package Keys', null, null, null, 1, 1, null, - ''type_specific'', - ''f'' + 'type_specific', + 'f' ); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select inline_1 (); @@ -377,234 +384,241 @@ -- Metadata for the apm_package_versions object. -create or replace function inline_2 () -returns integer as ' -declare + + +-- +-- procedure inline_2/0 +-- +CREATE OR REPLACE FUNCTION inline_2( + +) RETURNS integer AS $$ +DECLARE attr_id acs_attributes.attribute_id%TYPE; -begin +BEGIN attr_id := acs_object_type__create_type ( - ''apm_package_version'', - ''Package Version'', - ''Package Versions'', - ''acs_object'', - ''apm_package_versions'', - ''version_id'', - ''apm_package_version'', - ''f'', + 'apm_package_version', + 'Package Version', + 'Package Versions', + 'acs_object', + 'apm_package_versions', + 'version_id', + 'apm_package_version', + 'f', null, null ); attr_id := acs_attribute__create_attribute ( - ''apm_package_version'', - ''package_key'', - ''string'', - ''Package Key'', - ''Package Keys'', + 'apm_package_version', + 'package_key', + 'string', + 'Package Key', + 'Package Keys', null, null, null, 1, 1, null, - ''type_specific'', - ''f'' + 'type_specific', + 'f' ); attr_id := acs_attribute__create_attribute ( - ''apm_package_version'', - ''version_name'', - ''string'', - ''Version Name'', - ''Version Names'', + 'apm_package_version', + 'version_name', + 'string', + 'Version Name', + 'Version Names', null, null, null, 1, 1, null, - ''type_specific'', - ''f'' + 'type_specific', + 'f' ); attr_id := acs_attribute__create_attribute ( - ''apm_package_version'', - ''version_uri'', - ''string'', - ''Version URI'', - ''Version URIs'', + 'apm_package_version', + 'version_uri', + 'string', + 'Version URI', + 'Version URIs', null, null, null, 1, 1, null, - ''type_specific'', - ''f'' + 'type_specific', + 'f' ); attr_id := acs_attribute__create_attribute ( - ''apm_package_version'', - ''summary'', - ''string'', - ''Summary'', - ''Summaries'', + 'apm_package_version', + 'summary', + 'string', + 'Summary', + 'Summaries', null, null, null, 1, 1, null, - ''type_specific'', - ''f'' + 'type_specific', + 'f' ); attr_id := acs_attribute__create_attribute ( - ''apm_package_version'', - ''description_format'', - ''string'', - ''Description Format'', - ''Description Formats'', + 'apm_package_version', + 'description_format', + 'string', + 'Description Format', + 'Description Formats', null, null, null, 1, 1, null, - ''type_specific'', - ''f'' + 'type_specific', + 'f' ); attr_id := acs_attribute__create_attribute ( - ''apm_package_version'', - ''description'', - ''string'', - ''Description'', - ''Descriptions'', + 'apm_package_version', + 'description', + 'string', + 'Description', + 'Descriptions', null, null, null, 1, 1, null, - ''type_specific'', - ''f'' + 'type_specific', + 'f' ); attr_id := acs_attribute__create_attribute ( - ''apm_package_version'', - ''vendor'', - ''string'', - ''Vendor'', - ''Vendors'', + 'apm_package_version', + 'vendor', + 'string', + 'Vendor', + 'Vendors', null, null, null, 1, 1, null, - ''type_specific'', - ''f'' + 'type_specific', + 'f' ); attr_id := acs_attribute__create_attribute ( - ''apm_package_version'', - ''vendor_uri'', - ''string'', - ''Vendor URI'', - ''Vendor URIs'', + 'apm_package_version', + 'vendor_uri', + 'string', + 'Vendor URI', + 'Vendor URIs', null, null, null, 1, 1, null, - ''type_specific'', - ''f'' + 'type_specific', + 'f' ); attr_id := acs_attribute__create_attribute ( - ''apm_package_version'', - ''enabled_p'', - ''boolean'', - ''Enabled'', - ''Enabled'', + 'apm_package_version', + 'enabled_p', + 'boolean', + 'Enabled', + 'Enabled', null, null, null, 1, 1, null, - ''type_specific'', - ''f'' + 'type_specific', + 'f' ); attr_id := acs_attribute__create_attribute ( - ''apm_package_version'', - ''activation_date'', - ''date'', - ''Activation Date'', - ''Activation Dates'', + 'apm_package_version', + 'activation_date', + 'date', + 'Activation Date', + 'Activation Dates', null, null, null, 1, 1, null, - ''type_specific'', - ''f'' + 'type_specific', + 'f' ); attr_id := acs_attribute__create_attribute ( - ''apm_package_version'', - ''deactivation_date'', - ''date'', - ''Deactivation Date'', - ''Deactivation Dates'', + 'apm_package_version', + 'deactivation_date', + 'date', + 'Deactivation Date', + 'Deactivation Dates', null, null, null, 1, 1, null, - ''type_specific'', - ''f'' + 'type_specific', + 'f' ); attr_id := acs_attribute__create_attribute ( - ''apm_package_version'', - ''distribution_uri'', - ''string'', - ''Distribution URI'', - ''Distribution URIs'', + 'apm_package_version', + 'distribution_uri', + 'string', + 'Distribution URI', + 'Distribution URIs', null, null, null, 1, 1, null, - ''type_specific'', - ''f'' + 'type_specific', + 'f' ); attr_id := acs_attribute__create_attribute ( - ''apm_package_version'', - ''distribution_date'', - ''date'', - ''Distribution Date'', - ''Distribution Dates'', + 'apm_package_version', + 'distribution_date', + 'date', + 'Distribution Date', + 'Distribution Dates', null, null, null, 1, 1, null, - ''type_specific'', - ''f'' + 'type_specific', + 'f' ); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select inline_2 (); @@ -797,138 +811,145 @@ -- Metadata for the apm_parameter and apm_parameter_value system. -create or replace function inline_4 () -returns integer as ' -declare + + +-- +-- procedure inline_4/0 +-- +CREATE OR REPLACE FUNCTION inline_4( + +) RETURNS integer AS $$ +DECLARE attr_id acs_attributes.attribute_id%TYPE; -begin +BEGIN attr_id := acs_object_type__create_type ( - ''apm_parameter'', - ''Package Parameter'', - ''Package Parameters'', - ''acs_object'', - ''apm_parameters'', - ''parameter_id'', - ''apm_parameter'', - ''f'', + 'apm_parameter', + 'Package Parameter', + 'Package Parameters', + 'acs_object', + 'apm_parameters', + 'parameter_id', + 'apm_parameter', + 'f', null, null ); attr_id := acs_attribute__create_attribute ( - ''apm_parameter'', - ''package_key'', - ''string'', - ''Package Key'', - ''Package Keys'', + 'apm_parameter', + 'package_key', + 'string', + 'Package Key', + 'Package Keys', null, null, null, 1, 1, null, - ''type_specific'', - ''f'' + 'type_specific', + 'f' ); attr_id := acs_attribute__create_attribute ( - ''apm_parameter'', - ''parameter_name'', - ''string'', - ''Parameter Name'', - ''Parameter Name'', + 'apm_parameter', + 'parameter_name', + 'string', + 'Parameter Name', + 'Parameter Name', null, null, null, 1, 1, null, - ''type_specific'', - ''f'' + 'type_specific', + 'f' ); attr_id := acs_attribute__create_attribute ( - ''apm_parameter'', - ''scope'', - ''string'', - ''Scope'', - ''Scope'', + 'apm_parameter', + 'scope', + 'string', + 'Scope', + 'Scope', null, null, null, 1, 1, null, - ''type_specific'', - ''f'' + 'type_specific', + 'f' ); attr_id := acs_attribute__create_attribute ( - ''apm_parameter'', - ''datatype'', - ''string'', - ''Datatype'', - ''Datatypes'', + 'apm_parameter', + 'datatype', + 'string', + 'Datatype', + 'Datatypes', null, null, null, 1, 1, null, - ''type_specific'', - ''f'' + 'type_specific', + 'f' ); attr_id := acs_attribute__create_attribute ( - ''apm_parameter'', - ''default_value'', - ''string'', - ''Default Value'', - ''Default Values'', + 'apm_parameter', + 'default_value', + 'string', + 'Default Value', + 'Default Values', null, null, null, 1, 1, null, - ''type_specific'', - ''f'' + 'type_specific', + 'f' ); attr_id := acs_attribute__create_attribute ( - ''apm_parameter'', - ''min_n_values'', - ''number'', - ''Minimum Number of Values'', - ''Minimum Numer of Values Settings'', + 'apm_parameter', + 'min_n_values', + 'number', + 'Minimum Number of Values', + 'Minimum Numer of Values Settings', null, null, 1, 1, 1, null, - ''type_specific'', - ''f'' + 'type_specific', + 'f' ); attr_id := acs_attribute__create_attribute ( - ''apm_parameter'', - ''max_n_values'', - ''integer'', - ''Maximum Number of Values'', - ''Maximum Number of Values Settings'', + 'apm_parameter', + 'max_n_values', + 'integer', + 'Maximum Number of Values', + 'Maximum Number of Values Settings', null, null, 1, 1, 1, null, - ''type_specific'', - ''f'' + 'type_specific', + 'f' ); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select inline_4 (); @@ -938,74 +959,81 @@ -- show errors -create or replace function inline_5 () -returns integer as ' -declare + + +-- +-- procedure inline_5/0 +-- +CREATE OR REPLACE FUNCTION inline_5( + +) RETURNS integer AS $$ +DECLARE attr_id acs_attributes.attribute_id%TYPE; -begin +BEGIN attr_id := acs_object_type__create_type ( - ''apm_parameter_value'', - ''APM Package Parameter Value'', - ''APM Package Parameter Values'', - ''acs_object'', - ''apm_parameter_values'', - ''value_id'', - ''apm_parameter_value'', - ''f'', + 'apm_parameter_value', + 'APM Package Parameter Value', + 'APM Package Parameter Values', + 'acs_object', + 'apm_parameter_values', + 'value_id', + 'apm_parameter_value', + 'f', null, null ); attr_id := acs_attribute__create_attribute ( - ''apm_parameter_value'', - ''package_id'', - ''number'', - ''Package ID'', - ''Package IDs'', + 'apm_parameter_value', + 'package_id', + 'number', + 'Package ID', + 'Package IDs', null, null, null, 1, 1, null, - ''type_specific'', - ''f'' + 'type_specific', + 'f' ); attr_id := acs_attribute__create_attribute ( - ''apm_parameter_value'', - ''parameter_id'', - ''number'', - ''Parameter ID'', - ''Parameter IDs'', + 'apm_parameter_value', + 'parameter_id', + 'number', + 'Parameter ID', + 'Parameter IDs', null, null, null, 1, 1, null, - ''type_specific'', - ''f'' + 'type_specific', + 'f' ); attr_id := acs_attribute__create_attribute ( - ''apm_parameter_value'', - ''attr_value'', - ''string'', - ''Parameter Value'', - ''Parameter Values'', + 'apm_parameter_value', + 'attr_value', + 'string', + 'Parameter Value', + 'Parameter Values', null, null, null, 1, 1, null, - ''type_specific'', - ''f'' + 'type_specific', + 'f' ); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select inline_5 (); @@ -1063,27 +1091,34 @@ '; -create or replace function inline_6 () -returns integer as ' -declare + + +-- +-- procedure inline_6/0 +-- +CREATE OR REPLACE FUNCTION inline_6( + +) RETURNS integer AS $$ +DECLARE dummy integer; -begin +BEGIN -- Create a new object type for applications. dummy := acs_object_type__create_type ( - ''apm_application'', - ''Application'', - ''Applications'', - ''apm_package'', - ''apm_applications'', - ''application_id'', - ''apm_application'', - ''f'', + 'apm_application', + 'Application', + 'Applications', + 'apm_package', + 'apm_applications', + 'application_id', + 'apm_application', + 'f', null, null ); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select inline_6 (); @@ -1093,47 +1128,63 @@ -- show errors -create or replace function inline_7 () -returns integer as ' -declare + + +-- +-- procedure inline_7/0 +-- +CREATE OR REPLACE FUNCTION inline_7( + +) RETURNS integer AS $$ +DECLARE dummy integer; -begin +BEGIN -- Create a new object type for services. dummy := acs_object_type__create_type ( - ''apm_service'', - ''Service'', - ''Services'', - ''apm_package'', - ''apm_services'', - ''service_id'', - ''apm_service'', - ''f'', + 'apm_service', + 'Service', + 'Services', + 'apm_package', + 'apm_services', + 'service_id', + 'apm_service', + 'f', null, null ); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select inline_7 (); drop function inline_7 (); -create or replace function apm__register_package (varchar,varchar,varchar,varchar,varchar,boolean,boolean,boolean,boolean,varchar,integer) -returns integer as ' -declare - package_key alias for $1; - pretty_name alias for $2; - pretty_plural alias for $3; - package_uri alias for $4; - package_type alias for $5; - initial_install_p alias for $6; -- default ''f'' - singleton_p alias for $7; -- default ''f'' - implements_subsite_p alias for $8; -- default ''f'' - inherit_templates_p alias for $9; -- default ''f'' - spec_file_path alias for $10; -- default null - spec_file_mtime alias for $11; -- default null -begin + + +-- added +select define_function_args('apm__register_package','package_key,pretty_name,pretty_plural,package_uri,package_type,initial_install_p;f,singleton_p;f,implements_subsite_p;f,inherit_templates_p;f,spec_file_path;null,spec_file_mtime;null'); + +-- +-- procedure apm__register_package/11 +-- +CREATE OR REPLACE FUNCTION apm__register_package( + package_key varchar, + pretty_name varchar, + pretty_plural varchar, + package_uri varchar, + package_type varchar, + initial_install_p boolean, -- default 'f' + singleton_p boolean, -- default 'f' + implements_subsite_p boolean, -- default 'f' + inherit_templates_p boolean, -- default 'f' + spec_file_path varchar, -- default null + spec_file_mtime integer -- default null + +) RETURNS integer AS $$ +DECLARE +BEGIN PERFORM apm_package_type__create_type( package_key, pretty_name, @@ -1149,24 +1200,34 @@ ); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function update_package -create or replace function apm__update_package (varchar,varchar,varchar,varchar,varchar,boolean,boolean,boolean,boolean,varchar,integer) -returns varchar as ' -declare - package_key alias for $1; - pretty_name alias for $2; -- default null - pretty_plural alias for $3; -- default null - package_uri alias for $4; -- default null - package_type alias for $5; -- default null - initial_install_p alias for $6; -- default null - singleton_p alias for $7; -- default null - implements_subsite_p alias for $8; -- default ''f'' - inherit_templates_p alias for $9; -- default ''f'' - spec_file_path alias for $10; -- default null - spec_file_mtime alias for $11; -- default null -begin + + +-- added +select define_function_args('apm__update_package','package_key,pretty_name;null,pretty_plural;null,package_uri;null,package_type;null,initial_install_p;null,singleton_p;null,implements_subsite_p;f,inherit_templates_p;f,spec_file_path;null,spec_file_mtime;null'); + +-- +-- procedure apm__update_package/11 +-- +CREATE OR REPLACE FUNCTION apm__update_package( + package_key varchar, + pretty_name varchar, -- default null + pretty_plural varchar, -- default null + package_uri varchar, -- default null + package_type varchar, -- default null + initial_install_p boolean, -- default null + singleton_p boolean, -- default null + implements_subsite_p boolean, -- default 'f' + inherit_templates_p boolean, -- default 'f' + spec_file_path varchar, -- default null + spec_file_mtime integer -- default null + +) RETURNS varchar AS $$ +DECLARE +BEGIN return apm_package_type__update_type( package_key, @@ -1181,18 +1242,28 @@ spec_file_path, spec_file_mtime ); -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure unregister_package -create or replace function apm__unregister_package (varchar,boolean) -returns integer as ' -declare - package_key alias for $1; - p_cascade_p alias for $2; -- default ''t'' + + +-- added +select define_function_args('apm__unregister_package','package_key,cascade_p;t'); + +-- +-- procedure apm__unregister_package/2 +-- +CREATE OR REPLACE FUNCTION apm__unregister_package( + package_key varchar, + p_cascade_p boolean -- default 't' + +) RETURNS integer AS $$ +DECLARE v_cascade_p boolean; -begin +BEGIN if cascade_p is null then - v_cascade_p := ''t''; + v_cascade_p := 't'; else v_cascade_p := p_cascade_p; end if; @@ -1203,46 +1274,65 @@ ); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function register_p -create or replace function apm__register_p (varchar) -returns integer as ' -declare - register_p__package_key alias for $1; + + +-- added +select define_function_args('apm__register_p','package_key'); + +-- +-- procedure apm__register_p/1 +-- +CREATE OR REPLACE FUNCTION apm__register_p( + register_p__package_key varchar +) RETURNS integer AS $$ +DECLARE v_register_p integer; -begin +BEGIN select case when count(*) = 0 then 0 else 1 end into v_register_p from apm_package_types where package_key = register_p__package_key; return v_register_p; -end;' language 'plpgsql' stable; +END; +$$ LANGUAGE plpgsql stable; -- procedure register_application -create or replace function apm__register_application (varchar,varchar,varchar,varchar,boolean,boolean,boolean,boolean,varchar,integer) -returns integer as ' -declare - package_key alias for $1; - pretty_name alias for $2; - pretty_plural alias for $3; - package_uri alias for $4; - initial_install_p alias for $5; -- default ''f'' - singleton_p alias for $6; -- default ''f'' - implements_subsite_p alias for $7; -- default ''f'' - inherit_templates_p alias for $8; -- default ''f'' - spec_file_path alias for $9; -- default null - spec_file_mtime alias for $10; -- default null -begin + + +-- added +select define_function_args('apm__register_application','package_key,pretty_name,pretty_plural,package_uri,initial_install_p;f,singleton_p;f,implements_subsite_p;f,inherit_templates_p;f,spec_file_path;null,spec_file_mtime;null'); + +-- +-- procedure apm__register_application/10 +-- +CREATE OR REPLACE FUNCTION apm__register_application( + package_key varchar, + pretty_name varchar, + pretty_plural varchar, + package_uri varchar, + initial_install_p boolean, -- default 'f' + singleton_p boolean, -- default 'f' + implements_subsite_p boolean, -- default 'f' + inherit_templates_p boolean, -- default 'f' + spec_file_path varchar, -- default null + spec_file_mtime integer -- default null + +) RETURNS integer AS $$ +DECLARE +BEGIN PERFORM apm__register_package( package_key, pretty_name, pretty_plural, package_uri, - ''apm_application'', + 'apm_application', initial_install_p, singleton_p, implements_subsite_p, @@ -1252,19 +1342,29 @@ ); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure unregister_application -create or replace function apm__unregister_application (varchar,boolean) -returns integer as ' -declare - package_key alias for $1; - p_cascade_p alias for $2; -- default ''f'' + + +-- added +select define_function_args('apm__unregister_application','package_key,cascade_p;f'); + +-- +-- procedure apm__unregister_application/2 +-- +CREATE OR REPLACE FUNCTION apm__unregister_application( + package_key varchar, + p_cascade_p boolean -- default 'f' + +) RETURNS integer AS $$ +DECLARE v_cascade_p boolean; -begin +BEGIN if p_cascade_p is null then - v_cascade_p := ''f''; + v_cascade_p := 'f'; else v_cascade_p := p_cascade_p; end if; @@ -1275,30 +1375,40 @@ ); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure register_service -create or replace function apm__register_service (varchar,varchar,varchar,varchar,boolean,boolean,boolean,boolean,varchar,integer) -returns integer as ' -declare - package_key alias for $1; - pretty_name alias for $2; - pretty_plural alias for $3; - package_uri alias for $4; - initial_install_p alias for $5; -- default ''f'' - singleton_p alias for $6; -- default ''f'' - implements_subsite_p alias for $7; -- default ''f'' - inherit_templates_p alias for $8; -- default ''f'' - spec_file_path alias for $9; -- default null - spec_file_mtime alias for $10; -- default null -begin + + +-- added +select define_function_args('apm__register_service','package_key,pretty_name,pretty_plural,package_uri,initial_install_p;f,singleton_p;f,implements_subsite_p;f,inherit_templates_p;f,spec_file_path;null,spec_file_mtime;null'); + +-- +-- procedure apm__register_service/10 +-- +CREATE OR REPLACE FUNCTION apm__register_service( + package_key varchar, + pretty_name varchar, + pretty_plural varchar, + package_uri varchar, + initial_install_p boolean, -- default 'f' + singleton_p boolean, -- default 'f' + implements_subsite_p boolean, -- default 'f' + inherit_templates_p boolean, -- default 'f' + spec_file_path varchar, -- default null + spec_file_mtime integer -- default null + +) RETURNS integer AS $$ +DECLARE +BEGIN PERFORM apm__register_package( package_key, pretty_name, pretty_plural, package_uri, - ''apm_service'', + 'apm_service', initial_install_p, singleton_p, implements_subsite_p, @@ -1308,19 +1418,29 @@ ); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure unregister_service -create or replace function apm__unregister_service (varchar,boolean) -returns integer as ' -declare - package_key alias for $1; - p_cascade_p alias for $2; -- default ''f'' + + +-- added +select define_function_args('apm__unregister_service','package_key,cascade_p;f'); + +-- +-- procedure apm__unregister_service/2 +-- +CREATE OR REPLACE FUNCTION apm__unregister_service( + package_key varchar, + p_cascade_p boolean -- default 'f' + +) RETURNS integer AS $$ +DECLARE v_cascade_p boolean; -begin +BEGIN if p_cascade_p is null then - v_cascade_p := ''f''; + v_cascade_p := 'f'; else v_cascade_p := p_cascade_p; end if; @@ -1331,37 +1451,47 @@ ); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create or replace function apm__register_parameter (integer,varchar,varchar,varchar,varchar,varchar,varchar,varchar,integer,integer) -returns integer as ' -declare - register_parameter__parameter_id alias for $1; -- default null - register_parameter__package_key alias for $2; - register_parameter__parameter_name alias for $3; - register_parameter__description alias for $4; -- default null - register_parameter__scope alias for $5; - register_parameter__datatype alias for $6; -- default ''string'' - register_parameter__default_value alias for $7; -- default null - register_parameter__section_name alias for $8; -- default null - register_parameter__min_n_values alias for $9; -- default 1 - register_parameter__max_n_values alias for $10; -- default 1 + +-- added +select define_function_args('apm__register_parameter','parameter_id;null,package_key,parameter_name,description;null,scope,datatype;string,default_value;null,section_name;null,min_n_values;1,max_n_values;1'); + +-- +-- procedure apm__register_parameter/10 +-- +CREATE OR REPLACE FUNCTION apm__register_parameter( + register_parameter__parameter_id integer, -- default null + register_parameter__package_key varchar, + register_parameter__parameter_name varchar, + register_parameter__description varchar, -- default null + register_parameter__scope varchar, + register_parameter__datatype varchar, -- default 'string' + register_parameter__default_value varchar, -- default null + register_parameter__section_name varchar, -- default null + register_parameter__min_n_values integer, -- default 1 + register_parameter__max_n_values integer -- default 1 + +) RETURNS integer AS $$ +DECLARE + v_parameter_id apm_parameters.parameter_id%TYPE; v_value_id apm_parameter_values.value_id%TYPE; v_pkg record; -begin +BEGIN -- Create the new parameter. v_parameter_id := acs_object__new( register_parameter__parameter_id, - ''apm_parameter'', + 'apm_parameter', now(), null, null, null, - ''t'', - register_parameter__package_key || '' - '' || register_parameter__parameter_name, + 't', + register_parameter__package_key || ' - ' || register_parameter__parameter_name, null ); @@ -1376,7 +1506,7 @@ register_parameter__max_n_values); -- Propagate parameter to new instances. - if register_parameter__scope = ''instance'' then + if register_parameter__scope = 'instance' then for v_pkg in select package_id from apm_packages @@ -1398,45 +1528,62 @@ return v_parameter_id; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- For backwards compatibility, register a parameter with "instance" scope. -create or replace function apm__register_parameter (integer,varchar,varchar,varchar,varchar,varchar,varchar,integer,integer) -returns integer as ' -declare - register_parameter__parameter_id alias for $1; -- default null - register_parameter__package_key alias for $2; - register_parameter__parameter_name alias for $3; - register_parameter__description alias for $4; -- default null - register_parameter__datatype alias for $5; -- default ''string'' - register_parameter__default_value alias for $6; -- default null - register_parameter__section_name alias for $7; -- default null - register_parameter__min_n_values alias for $8; -- default 1 - register_parameter__max_n_values alias for $9; -- default 1 -begin + +-- +-- procedure apm__register_parameter/9 +-- +CREATE OR REPLACE FUNCTION apm__register_parameter( + register_parameter__parameter_id integer, -- default null + register_parameter__package_key varchar, + register_parameter__parameter_name varchar, + register_parameter__description varchar, -- default null + register_parameter__datatype varchar, -- default 'string' + register_parameter__default_value varchar, -- default null + register_parameter__section_name varchar, -- default null + register_parameter__min_n_values integer, -- default 1 + register_parameter__max_n_values integer -- default 1 + +) RETURNS integer AS $$ +DECLARE + +BEGIN return apm__register_parameter(register_parameter__parameter_id, register_parameter__package_key, register_parameter__parameter_name, register_parameter__description, - ''instance'', register_parameter__datatype, + 'instance', register_parameter__datatype, register_parameter__default_value, register_parameter__section_name, register_parameter__min_n_values, register_parameter__max_n_values); -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function update_parameter -create or replace function apm__update_parameter (integer,varchar,varchar,varchar,varchar,varchar,integer,integer) -returns varchar as ' -declare - update_parameter__parameter_id alias for $1; - update_parameter__parameter_name alias for $2; -- default null - update_parameter__description alias for $3; -- default null - update_parameter__datatype alias for $4; -- default ''string'' - update_parameter__default_value alias for $5; -- default null - update_parameter__section_name alias for $6; -- default null - update_parameter__min_n_values alias for $7; -- default 1 - update_parameter__max_n_values alias for $8; -- default 1 -begin + + +-- added +select define_function_args('apm__update_parameter','parameter_id,parameter_name;null,description;null,datatype;string,default_value;null,section_name;null,min_n_values;1,max_n_values;1'); + +-- +-- procedure apm__update_parameter/8 +-- +CREATE OR REPLACE FUNCTION apm__update_parameter( + update_parameter__parameter_id integer, + update_parameter__parameter_name varchar, -- default null + update_parameter__description varchar, -- default null + update_parameter__datatype varchar, -- default 'string' + update_parameter__default_value varchar, -- default null + update_parameter__section_name varchar, -- default null + update_parameter__min_n_values integer, -- default 1 + update_parameter__max_n_values integer -- default 1 + +) RETURNS varchar AS $$ +DECLARE +BEGIN update apm_parameters set parameter_name = coalesce(update_parameter__parameter_name, parameter_name), default_value = coalesce(update_parameter__default_value, default_value), @@ -1448,56 +1595,83 @@ where parameter_id = update_parameter__parameter_id; update acs_objects - set title = (select package_key || '': Parameter '' || parameter_name + set title = (select package_key || ': Parameter ' || parameter_name from apm_parameters where parameter_id = update_parameter__parameter_id) where object_id = update_parameter__parameter_id; return parameter_id; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function parameter_p -create or replace function apm__parameter_p (varchar,varchar) -returns integer as ' -declare - parameter_p__package_key alias for $1; - parameter_p__parameter_name alias for $2; + + +-- added +select define_function_args('apm__parameter_p','package_key,parameter_name'); + +-- +-- procedure apm__parameter_p/2 +-- +CREATE OR REPLACE FUNCTION apm__parameter_p( + parameter_p__package_key varchar, + parameter_p__parameter_name varchar +) RETURNS integer AS $$ +DECLARE v_parameter_p integer; -begin +BEGIN select case when count(*) = 0 then 0 else 1 end into v_parameter_p from apm_parameters where package_key = parameter_p__package_key and parameter_name = parameter_p__parameter_name; return v_parameter_p; -end;' language 'plpgsql' stable; +END; +$$ LANGUAGE plpgsql stable; -- procedure unregister_parameter -create or replace function apm__unregister_parameter (integer) -returns integer as ' -declare - unregister_parameter__parameter_id alias for $1; -- default null -begin + + +-- added +select define_function_args('apm__unregister_parameter','parameter_id;null'); + +-- +-- procedure apm__unregister_parameter/1 +-- +CREATE OR REPLACE FUNCTION apm__unregister_parameter( + unregister_parameter__parameter_id integer -- default null + +) RETURNS integer AS $$ +DECLARE +BEGIN delete from apm_parameter_values where parameter_id = unregister_parameter__parameter_id; delete from apm_parameters where parameter_id = unregister_parameter__parameter_id; PERFORM acs_object__delete(unregister_parameter__parameter_id); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create or replace function apm__id_for_name (integer,varchar) -returns integer as ' -declare - id_for_name__package_id alias for $1; - id_for_name__parameter_name alias for $2; + + +-- added + +-- +-- procedure apm__id_for_name/2 +-- +CREATE OR REPLACE FUNCTION apm__id_for_name( + id_for_name__package_id integer, + id_for_name__parameter_name varchar +) RETURNS integer AS $$ +DECLARE a_parameter_id apm_parameters.parameter_id%TYPE; -begin +BEGIN select parameter_id into a_parameter_id from apm_parameters where parameter_name = id_for_name__parameter_name @@ -1506,42 +1680,59 @@ if NOT FOUND then - raise EXCEPTION ''-20000: The specified package % AND/OR parameter % do not exist in the system'', id_for_name__package_id, id_for_name__parameter_name; + raise EXCEPTION '-20000: The specified package % AND/OR parameter % do not exist in the system', id_for_name__package_id, id_for_name__parameter_name; end if; return a_parameter_id; -end;' language 'plpgsql' stable strict; +END; +$$ LANGUAGE plpgsql stable strict; -create or replace function apm__id_for_name (varchar,varchar) -returns integer as ' -declare - id_for_name__package_key alias for $1; - id_for_name__parameter_name alias for $2; + + +-- added +select define_function_args('apm__id_for_name','package_key,parameter_name'); + +-- +-- procedure apm__id_for_name/2 +-- +CREATE OR REPLACE FUNCTION apm__id_for_name( + id_for_name__package_key varchar, + id_for_name__parameter_name varchar +) RETURNS integer AS $$ +DECLARE a_parameter_id apm_parameters.parameter_id%TYPE; -begin +BEGIN select parameter_id into a_parameter_id from apm_parameters p where p.parameter_name = id_for_name__parameter_name and p.package_key = id_for_name__package_key; if NOT FOUND then - raise EXCEPTION ''-20000: The specified package % AND/OR parameter % do not exist in the system'', id_for_name__package_key, id_for_name__parameter_name; + raise EXCEPTION '-20000: The specified package % AND/OR parameter % do not exist in the system', id_for_name__package_key, id_for_name__parameter_name; end if; return a_parameter_id; -end;' language 'plpgsql' stable strict; +END; +$$ LANGUAGE plpgsql stable strict; -create or replace function apm__get_value (integer,varchar) -returns varchar as ' -declare - get_value__package_id alias for $1; - get_value__parameter_name alias for $2; + + +-- added + +-- +-- procedure apm__get_value/2 +-- +CREATE OR REPLACE FUNCTION apm__get_value( + get_value__package_id integer, + get_value__parameter_name varchar +) RETURNS varchar AS $$ +DECLARE v_parameter_id apm_parameter_values.parameter_id%TYPE; value apm_parameter_values.attr_value%TYPE; -begin +BEGIN v_parameter_id := apm__id_for_name (get_value__package_id, get_value__parameter_name); select attr_value into value from apm_parameter_values v @@ -1550,16 +1741,25 @@ return value; -end;' language 'plpgsql' stable strict; +END; +$$ LANGUAGE plpgsql stable strict; -create or replace function apm__get_value (varchar,varchar) -returns varchar as ' -declare - get_value__package_key alias for $1; - get_value__parameter_name alias for $2; + + +-- added +select define_function_args('apm__get_value','package_key,parameter_name'); + +-- +-- procedure apm__get_value/2 +-- +CREATE OR REPLACE FUNCTION apm__get_value( + get_value__package_key varchar, + get_value__parameter_name varchar +) RETURNS varchar AS $$ +DECLARE v_parameter_id apm_parameter_values.parameter_id%TYPE; value apm_parameter_values.attr_value%TYPE; -begin +BEGIN v_parameter_id := apm__id_for_name (get_value__package_key, get_value__parameter_name); select attr_value into value from apm_parameter_values v @@ -1568,17 +1768,25 @@ return value; -end;' language 'plpgsql' stable strict; +END; +$$ LANGUAGE plpgsql stable strict; -create or replace function apm__set_value (integer,varchar,varchar) -returns integer as ' -declare - set_value__package_id alias for $1; - set_value__parameter_name alias for $2; - set_value__attr_value alias for $3; + + +-- added + +-- +-- procedure apm__set_value/3 +-- +CREATE OR REPLACE FUNCTION apm__set_value( + set_value__package_id integer, + set_value__parameter_name varchar, + set_value__attr_value varchar +) RETURNS integer AS $$ +DECLARE v_parameter_id apm_parameter_values.parameter_id%TYPE; v_value_id apm_parameter_values.value_id%TYPE; -begin +BEGIN v_parameter_id := apm__id_for_name (set_value__package_id, set_value__parameter_name); -- Determine if the value exists @@ -1601,17 +1809,26 @@ end if; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create or replace function apm__set_value (varchar,varchar,varchar) -returns integer as ' -declare - set_value__package_key alias for $1; - set_value__parameter_name alias for $2; - set_value__attr_value alias for $3; + + +-- added +select define_function_args('apm__set_value','package_key,parameter_name,attr_value'); + +-- +-- procedure apm__set_value/3 +-- +CREATE OR REPLACE FUNCTION apm__set_value( + set_value__package_key varchar, + set_value__parameter_name varchar, + set_value__attr_value varchar +) RETURNS integer AS $$ +DECLARE v_parameter_id apm_parameter_values.parameter_id%TYPE; v_value_id apm_parameter_values.value_id%TYPE; -begin +BEGIN v_parameter_id := apm__id_for_name (set_value__package_key, set_value__parameter_name); -- Determine if the value exists @@ -1634,49 +1851,68 @@ end if; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create or replace function apm_package__is_child(varchar, varchar) returns boolean as ' -declare - parent_package_key alias for $1; - child_package_key alias for $2; + + +-- added +select define_function_args('apm_package__is_child','parent_package_key,child_package_key'); + +-- +-- procedure apm_package__is_child/2 +-- +CREATE OR REPLACE FUNCTION apm_package__is_child( + parent_package_key varchar, + child_package_key varchar +) RETURNS boolean AS $$ +DECLARE dependency record; -begin +BEGIN if parent_package_key = child_package_key then - return ''t''; + return 't'; end if; for dependency in select apd.service_uri from apm_package_versions apv, apm_package_dependencies apd where apd.version_id = apv.version_id and apv.enabled_p - and apd.dependency_type in (''embeds'', ''extends'') + and apd.dependency_type in ('embeds', 'extends') and apv.package_key = child_package_key loop if dependency.service_uri = parent_package_key or apm_package__is_child(parent_package_key, dependency.service_uri) then - return ''t''; + return 't'; end if; end loop; - return ''f''; -end;' language 'plpgsql'; + return 'f'; +END; +$$ LANGUAGE plpgsql; -create or replace function apm_package__initialize_parameters (integer,varchar) -returns integer as ' -declare - ip__package_id alias for $1; - ip__package_key alias for $2; + + +-- added +select define_function_args('apm_package__initialize_parameters','package_id,package_key'); + +-- +-- procedure apm_package__initialize_parameters/2 +-- +CREATE OR REPLACE FUNCTION apm_package__initialize_parameters( + ip__package_id integer, + ip__package_key varchar +) RETURNS integer AS $$ +DECLARE v_value_id apm_parameter_values.value_id%TYPE; cur_val record; -begin +BEGIN -- need to initialize all params for this type for cur_val in select parameter_id, default_value from apm_parameters where package_key = ip__package_key - and scope = ''instance'' + and scope = 'instance' loop v_value_id := apm_parameter_value__new( null, @@ -1687,27 +1923,37 @@ end loop; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function new -create or replace function apm_package__new (integer,varchar,varchar,varchar,timestamptz,integer,varchar,integer) -returns integer as ' -declare - new__package_id alias for $1; -- default null - new__instance_name alias for $2; -- default null - new__package_key alias for $3; - new__object_type alias for $4; -- default ''apm_package'' - new__creation_date alias for $5; -- default now() - new__creation_user alias for $6; -- default null - new__creation_ip alias for $7; -- default null - new__context_id alias for $8; -- default null + + +-- added +select define_function_args('apm_package__new','package_id;null,instance_name;null,package_key,object_type;apm_package,creation_date;now(),creation_user;null,creation_ip;null,context_id;null'); + +-- +-- procedure apm_package__new/8 +-- +CREATE OR REPLACE FUNCTION apm_package__new( + new__package_id integer, -- default null + new__instance_name varchar, -- default null + new__package_key varchar, + new__object_type varchar, -- default 'apm_package' + new__creation_date timestamptz, -- default now() + new__creation_user integer, -- default null + new__creation_ip varchar, -- default null + new__context_id integer -- default null + +) RETURNS integer AS $$ +DECLARE v_singleton_p integer; v_package_type apm_package_types.package_type%TYPE; v_num_instances integer; v_package_id apm_packages.package_id%TYPE; v_instance_name apm_packages.instance_name%TYPE; -begin +BEGIN v_singleton_p := apm_package__singleton_p( new__package_key ); @@ -1730,8 +1976,8 @@ new__creation_ip, new__context_id ); - if new__instance_name is null or new__instance_name = '''' then - v_instance_name := new__package_key || '' '' || v_package_id; + if new__instance_name is null or new__instance_name = '' then + v_instance_name := new__package_key || ' ' || v_package_id; else v_instance_name := new__instance_name; end if; @@ -1750,7 +1996,7 @@ package_id = v_package_id where object_id = v_package_id; - if v_package_type = ''apm_application'' then + if v_package_type = 'apm_application' then insert into apm_applications (application_id) values @@ -1770,14 +2016,24 @@ return v_package_id; end if; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create or replace function apm_package__delete (integer) returns integer as ' -declare - delete__package_id alias for $1; + + +-- added +select define_function_args('apm_package__delete','package_id'); + +-- +-- procedure apm_package__delete/1 +-- +CREATE OR REPLACE FUNCTION apm_package__delete( + delete__package_id integer +) RETURNS integer AS $$ +DECLARE cur_val record; v_folder_row record; -begin +BEGIN -- Delete all parameters. for cur_val in select value_id from apm_parameter_values where package_id = delete__package_id loop @@ -1790,7 +2046,7 @@ from cr_folders where package_id = delete__package_id loop - perform content_folder__del(v_folder_row.folder_id,''t''); + perform content_folder__del(v_folder_row.folder_id,'t'); end loop; delete from apm_applications where application_id = delete__package_id; @@ -1808,70 +2064,120 @@ ); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create or replace function apm_package__initial_install_p (varchar) returns integer as ' -declare - initial_install_p__package_key alias for $1; + + +-- added +select define_function_args('apm_package__initial_install_p','package_key'); + +-- +-- procedure apm_package__initial_install_p/1 +-- +CREATE OR REPLACE FUNCTION apm_package__initial_install_p( + initial_install_p__package_key varchar +) RETURNS integer AS $$ +DECLARE v_initial_install_p integer; -begin +BEGIN select 1 into v_initial_install_p from apm_package_types where package_key = initial_install_p__package_key - and initial_install_p = ''t''; + and initial_install_p = 't'; if NOT FOUND then return 0; else return v_initial_install_p; end if; -end;' language 'plpgsql' stable; +END; +$$ LANGUAGE plpgsql stable; -create or replace function apm_package__singleton_p (varchar) returns integer as ' -declare - singleton_p__package_key alias for $1; + + +-- added +select define_function_args('apm_package__singleton_p','package_key'); + +-- +-- procedure apm_package__singleton_p/1 +-- +CREATE OR REPLACE FUNCTION apm_package__singleton_p( + singleton_p__package_key varchar +) RETURNS integer AS $$ +DECLARE v_singleton_p integer; -begin +BEGIN select count(*) into v_singleton_p from apm_package_types where package_key = singleton_p__package_key - and singleton_p = ''t''; + and singleton_p = 't'; return v_singleton_p; -end;' language 'plpgsql' stable; +END; +$$ LANGUAGE plpgsql stable; -create or replace function apm_package__num_instances (varchar) returns integer as ' -declare - num_instances__package_key alias for $1; + + +-- added +select define_function_args('apm_package__num_instances','package_key'); + +-- +-- procedure apm_package__num_instances/1 +-- +CREATE OR REPLACE FUNCTION apm_package__num_instances( + num_instances__package_key varchar +) RETURNS integer AS $$ +DECLARE v_num_instances integer; -begin +BEGIN select count(*) into v_num_instances from apm_packages where package_key = num_instances__package_key; return v_num_instances; -end;' language 'plpgsql' stable; +END; +$$ LANGUAGE plpgsql stable; -create or replace function apm_package__name (integer) returns varchar as ' -declare - name__package_id alias for $1; + + +-- added +select define_function_args('apm_package__name','package_id'); + +-- +-- procedure apm_package__name/1 +-- +CREATE OR REPLACE FUNCTION apm_package__name( + name__package_id integer +) RETURNS varchar AS $$ +DECLARE v_result apm_packages.instance_name%TYPE; -begin +BEGIN select instance_name into v_result from apm_packages where package_id = name__package_id; return v_result; -end;' language 'plpgsql' stable strict; +END; +$$ LANGUAGE plpgsql stable strict; -create or replace function apm_package__highest_version (varchar) returns integer as ' -declare - highest_version__package_key alias for $1; + + +-- added +select define_function_args('apm_package__highest_version','package_key'); + +-- +-- procedure apm_package__highest_version/1 +-- +CREATE OR REPLACE FUNCTION apm_package__highest_version( + highest_version__package_key varchar +) RETURNS integer AS $$ +DECLARE v_version_id apm_package_versions.version_id%TYPE; v_max_version varchar; -begin +BEGIN select max(apm_package_version__sortable_version_name(v.version_name)) into v_max_version from apm_package_version_info v where v.package_key = highest_version__package_key; @@ -1883,13 +2189,23 @@ else return v_version_id; end if; -end;' language 'plpgsql' stable; +END; +$$ LANGUAGE plpgsql stable; -create or replace function apm_package__parent_id (integer) returns integer as ' -declare - apm_package__parent_id__package_id alias for $1; + + +-- added +select define_function_args('apm_package__parent_id','parent_id__package_id'); + +-- +-- procedure apm_package__parent_id/1 +-- +CREATE OR REPLACE FUNCTION apm_package__parent_id( + apm_package__parent_id__package_id integer +) RETURNS integer AS $$ +DECLARE v_package_id apm_packages.package_id%TYPE; -begin +BEGIN select sn1.object_id into v_package_id from site_nodes sn1 @@ -1899,28 +2215,39 @@ return v_package_id; -end;' language 'plpgsql' stable strict; +END; +$$ LANGUAGE plpgsql stable strict; -- create or replace package body apm_package_version -create or replace function apm_package_version__new (integer,varchar,varchar,varchar,varchar,varchar,varchar,timestamptz,varchar,varchar,varchar,boolean,boolean) returns integer as ' -declare - apm_pkg_ver__version_id alias for $1; -- default null - apm_pkg_ver__package_key alias for $2; - apm_pkg_ver__version_name alias for $3; -- default null - apm_pkg_ver__version_uri alias for $4; - apm_pkg_ver__summary alias for $5; - apm_pkg_ver__description_format alias for $6; - apm_pkg_ver__description alias for $7; - apm_pkg_ver__release_date alias for $8; - apm_pkg_ver__vendor alias for $9; - apm_pkg_ver__vendor_uri alias for $10; - apm_pkg_ver__auto_mount alias for $11; - apm_pkg_ver__installed_p alias for $12; -- default ''f'' - apm_pkg_ver__data_model_loaded_p alias for $13; -- default ''f'' + + +-- added +select define_function_args('apm_package_version__new','version_id;null,package_key,version_name;null,version_uri,summary,description_format,description,release_date,vendor,vendor_uri,auto_mount,installed_p;f,data_model_loaded_p;f'); + +-- +-- procedure apm_package_version__new/13 +-- +CREATE OR REPLACE FUNCTION apm_package_version__new( + apm_pkg_ver__version_id integer, -- default null + apm_pkg_ver__package_key varchar, + apm_pkg_ver__version_name varchar, -- default null + apm_pkg_ver__version_uri varchar, + apm_pkg_ver__summary varchar, + apm_pkg_ver__description_format varchar, + apm_pkg_ver__description varchar, + apm_pkg_ver__release_date timestamptz, + apm_pkg_ver__vendor varchar, + apm_pkg_ver__vendor_uri varchar, + apm_pkg_ver__auto_mount varchar, + apm_pkg_ver__installed_p boolean, -- default 'f' + apm_pkg_ver__data_model_loaded_p boolean -- default 'f' + +) RETURNS integer AS $$ +DECLARE v_version_id apm_package_versions.version_id%TYPE; -begin +BEGIN if apm_pkg_ver__version_id is null then - select nextval(''t_acs_object_id_seq'') + select nextval('t_acs_object_id_seq') into v_version_id from dual; else @@ -1929,13 +2256,13 @@ v_version_id := acs_object__new( v_version_id, - ''apm_package_version'', + 'apm_package_version', now(), null, null, null, - ''t'', - apm_pkg_ver__package_key || '', Version '' || apm_pkg_ver__version_name, + 't', + apm_pkg_ver__package_key || ', Version ' || apm_pkg_ver__version_name, null ); @@ -1951,15 +2278,24 @@ return v_version_id; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure delete -create or replace function apm_package_version__delete (integer) -returns integer as ' -declare - delete__version_id alias for $1; -begin + + +-- added +select define_function_args('apm_package_version__delete','version_id'); + +-- +-- procedure apm_package_version__delete/1 +-- +CREATE OR REPLACE FUNCTION apm_package_version__delete( + delete__version_id integer +) RETURNS integer AS $$ +DECLARE +BEGIN delete from apm_package_owners where version_id = delete__version_id; @@ -1972,50 +2308,78 @@ PERFORM acs_object__delete(delete__version_id); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure enable -create or replace function apm_package_version__enable (integer) -returns integer as ' -declare - enable__version_id alias for $1; -begin - update apm_package_versions set enabled_p = ''t'' + + +-- added +select define_function_args('apm_package_version__enable','version_id'); + +-- +-- procedure apm_package_version__enable/1 +-- +CREATE OR REPLACE FUNCTION apm_package_version__enable( + enable__version_id integer +) RETURNS integer AS $$ +DECLARE +BEGIN + update apm_package_versions set enabled_p = 't' where version_id = enable__version_id; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure disable -create or replace function apm_package_version__disable (integer) -returns integer as ' -declare - disable__version_id alias for $1; -begin + + +-- added +select define_function_args('apm_package_version__disable','version_id'); + +-- +-- procedure apm_package_version__disable/1 +-- +CREATE OR REPLACE FUNCTION apm_package_version__disable( + disable__version_id integer +) RETURNS integer AS $$ +DECLARE +BEGIN update apm_package_versions - set enabled_p = ''f'' + set enabled_p = 'f' where version_id = disable__version_id; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function copy -create or replace function apm_package_version__copy (integer,integer,varchar,varchar,boolean) -returns integer as ' -declare - copy__version_id alias for $1; - copy__new_version_id alias for $2; -- default null - copy__new_version_name alias for $3; - copy__new_version_uri alias for $4; - copy__copy_owners_p alias for $5; + + +-- added +select define_function_args('apm_package_version__copy','version_id,new_version_id;null,new_version_name,new_version_uri,copy_owners_p'); + +-- +-- procedure apm_package_version__copy/5 +-- +CREATE OR REPLACE FUNCTION apm_package_version__copy( + copy__version_id integer, + copy__new_version_id integer, -- default null + copy__new_version_name varchar, + copy__new_version_uri varchar, + copy__copy_owners_p boolean + +) RETURNS integer AS $$ +DECLARE v_version_id integer; -begin +BEGIN v_version_id := acs_object__new( copy__new_version_id, - ''apm_package_version'', + 'apm_package_version', now(), null, null, @@ -2032,13 +2396,13 @@ where version_id = copy__version_id; update acs_objects - set title = (select v.package_key || '', Version '' || v.version_name + set title = (select v.package_key || ', Version ' || v.version_name from apm_package_versions v where v.version_id = copy__version_id) where object_id = copy__version_id; insert into apm_package_dependencies(dependency_id, version_id, dependency_type, service_uri, service_version) - select nextval(''t_acs_object_id_seq''), v_version_id, dependency_type, service_uri, service_version + select nextval('t_acs_object_id_seq'), v_version_id, dependency_type, service_uri, service_version from apm_package_dependencies where version_id = copy__version_id; @@ -2056,29 +2420,39 @@ return v_version_id; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function edit -create or replace function apm_package_version__edit (integer,integer,varchar,varchar,varchar,varchar,varchar,timestamptz,varchar,varchar,varchar,boolean,boolean) -returns integer as ' -declare - edit__new_version_id alias for $1; -- default null - edit__version_id alias for $2; - edit__version_name alias for $3; -- default null - edit__version_uri alias for $4; - edit__summary alias for $5; - edit__description_format alias for $6; - edit__description alias for $7; - edit__release_date alias for $8; - edit__vendor alias for $9; - edit__vendor_uri alias for $10; - edit__auto_mount alias for $11; - edit__installed_p alias for $12; -- default ''f'' - edit__data_model_loaded_p alias for $13; -- default ''f'' + + +-- added +select define_function_args('apm_package_version__edit','new_version_id;null,version_id,version_name;null,version_uri,summary,description_format,description,release_date,vendor,vendor_uri,auto_mount,installed_p;f,data_model_loaded_p;f'); + +-- +-- procedure apm_package_version__edit/13 +-- +CREATE OR REPLACE FUNCTION apm_package_version__edit( + edit__new_version_id integer, -- default null + edit__version_id integer, + edit__version_name varchar, -- default null + edit__version_uri varchar, + edit__summary varchar, + edit__description_format varchar, + edit__description varchar, + edit__release_date timestamptz, + edit__vendor varchar, + edit__vendor_uri varchar, + edit__auto_mount varchar, + edit__installed_p boolean, -- default 'f' + edit__data_model_loaded_p boolean -- default 'f' + +) RETURNS integer AS $$ +DECLARE v_version_id apm_package_versions.version_id%TYPE; version_unchanged_p integer; -begin +BEGIN -- Determine if version has changed. select case when count(*) = 0 then 0 else 1 end into version_unchanged_p from apm_package_versions @@ -2090,7 +2464,7 @@ edit__new_version_id, edit__version_name, edit__version_uri, - ''f'' + 'f' ); else v_version_id := edit__version_id; @@ -2101,7 +2475,7 @@ summary = edit__summary, description_format = edit__description_format, description = edit__description, - release_date = date_trunc(''days'',now()), + release_date = date_trunc('days',now()), vendor = edit__vendor, vendor_uri = edit__vendor_uri, auto_mount = edit__auto_mount, @@ -2111,79 +2485,116 @@ return v_version_id; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function add_interface -create or replace function apm_package_version__add_interface (integer,integer,varchar,varchar) -returns integer as ' -declare - add_interface__interface_id alias for $1; -- default null - add_interface__version_id alias for $2; - add_interface__interface_uri alias for $3; - add_interface__interface_version alias for $4; + + +-- added +select define_function_args('apm_package_version__add_interface','interface_id;null,version_id,interface_uri,interface_version'); + +-- +-- procedure apm_package_version__add_interface/4 +-- +CREATE OR REPLACE FUNCTION apm_package_version__add_interface( + add_interface__interface_id integer, -- default null + add_interface__version_id integer, + add_interface__interface_uri varchar, + add_interface__interface_version varchar + +) RETURNS integer AS $$ +DECLARE v_dep_id apm_package_dependencies.dependency_id%TYPE; -begin +BEGIN if add_interface__interface_id is null then - select nextval(''t_acs_object_id_seq'') into v_dep_id from dual; + select nextval('t_acs_object_id_seq') into v_dep_id from dual; else v_dep_id := add_interface__interface_id; end if; insert into apm_package_dependencies (dependency_id, version_id, dependency_type, service_uri, service_version) values - (v_dep_id, add_interface__version_id, ''provides'', add_interface__interface_uri, + (v_dep_id, add_interface__version_id, 'provides', add_interface__interface_uri, add_interface__interface_version); return v_dep_id; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure remove_interface -create or replace function apm_package_version__remove_interface (integer) -returns integer as ' -declare - remove_interface__interface_id alias for $1; -begin + + +-- added + +-- +-- procedure apm_package_version__remove_interface/1 +-- +CREATE OR REPLACE FUNCTION apm_package_version__remove_interface( + remove_interface__interface_id integer +) RETURNS integer AS $$ +DECLARE +BEGIN delete from apm_package_dependencies where dependency_id = remove_interface__interface_id; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure remove_interface -create or replace function apm_package_version__remove_interface (varchar,varchar,integer) -returns integer as ' -declare - remove_interface__interface_uri alias for $1; - remove_interface__interface_version alias for $2; - remove_interface__version_id alias for $3; + + +-- added +select define_function_args('apm_package_version__remove_interface','interface_uri,interface_version,version_id'); + +-- +-- procedure apm_package_version__remove_interface/3 +-- +CREATE OR REPLACE FUNCTION apm_package_version__remove_interface( + remove_interface__interface_uri varchar, + remove_interface__interface_version varchar, + remove_interface__version_id integer +) RETURNS integer AS $$ +DECLARE v_dep_id apm_package_dependencies.dependency_id%TYPE; -begin +BEGIN select dependency_id into v_dep_id from apm_package_dependencies where service_uri = remove_interface__interface_uri and interface_version = remove_interface__interface_version; PERFORM apm_package_version__remove_interface(v_dep_id); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function add_dependency -create or replace function apm_package_version__add_dependency (varchar,integer,integer,varchar,varchar) -returns integer as ' -declare - add_dependency__dependency_type alias for $1; - add_dependency__dependency_id alias for $2; -- default null - add_dependency__version_id alias for $3; - add_dependency__dependency_uri alias for $4; - add_dependency__dependency_version alias for $5; + + +-- added +select define_function_args('apm_package_version__add_dependency','dependency_type,dependency_id;null,version_id,dependency_uri,dependency_version'); + +-- +-- procedure apm_package_version__add_dependency/5 +-- +CREATE OR REPLACE FUNCTION apm_package_version__add_dependency( + add_dependency__dependency_type varchar, + add_dependency__dependency_id integer, -- default null + add_dependency__version_id integer, + add_dependency__dependency_uri varchar, + add_dependency__dependency_version varchar + +) RETURNS integer AS $$ +DECLARE v_dep_id apm_package_dependencies.dependency_id%TYPE; -begin +BEGIN if add_dependency__dependency_id is null then - select nextval(''t_acs_object_id_seq'') into v_dep_id from dual; + select nextval('t_acs_object_id_seq') into v_dep_id from dual; else v_dep_id := add_dependency__dependency_id; end if; @@ -2196,124 +2607,159 @@ return v_dep_id; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure remove_dependency -create or replace function apm_package_version__remove_dependency (integer) -returns integer as ' -declare - remove_dependency__dependency_id alias for $1; -begin + + +-- added + +-- +-- procedure apm_package_version__remove_dependency/1 +-- +CREATE OR REPLACE FUNCTION apm_package_version__remove_dependency( + remove_dependency__dependency_id integer +) RETURNS integer AS $$ +DECLARE +BEGIN delete from apm_package_dependencies where dependency_id = remove_dependency__dependency_id; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure remove_dependency -create or replace function apm_package_version__remove_dependency (varchar,varchar,integer) -returns integer as ' -declare - remove_dependency__dependency_uri alias for $1; - remove_dependency__dependency_version alias for $2; - remove_dependency__version_id alias for $3; + + +-- added +select define_function_args('apm_package_version__remove_dependency','dependency_uri,dependency_version,version_id'); + +-- +-- procedure apm_package_version__remove_dependency/3 +-- +CREATE OR REPLACE FUNCTION apm_package_version__remove_dependency( + remove_dependency__dependency_uri varchar, + remove_dependency__dependency_version varchar, + remove_dependency__version_id integer +) RETURNS integer AS $$ +DECLARE v_dep_id apm_package_dependencies.dependency_id%TYPE; -begin +BEGIN select dependency_id into v_dep_id from apm_package_dependencies where service_uri = remove_dependency__dependency_uri and service_version = remove_dependency__dependency_version; PERFORM apm_package_version__remove_dependency(v_dep_id); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function sortable_version_name -create or replace function apm_package_version__sortable_version_name (varchar) -returns varchar as ' -declare - version_name alias for $1; + + +-- added +select define_function_args('apm_package_version__sortable_version_name','version_name'); + +-- +-- procedure apm_package_version__sortable_version_name/1 +-- +CREATE OR REPLACE FUNCTION apm_package_version__sortable_version_name( + version_name varchar +) RETURNS varchar AS $$ +DECLARE a_fields integer; a_start integer; a_end integer; - a_order varchar(1000) default ''''; + a_order varchar(1000) default ''; a_char char(1); - a_seen_letter boolean default ''f''; -begin + a_seen_letter boolean default 'f'; +BEGIN a_fields := 0; a_start := 1; loop a_end := a_start; -- keep incrementing a_end until we run into a non-number - while substr(version_name, a_end, 1) >= ''0'' and substr(version_name, a_end, 1) <= ''9'' loop + while substr(version_name, a_end, 1) >= '0' and substr(version_name, a_end, 1) <= '9' loop a_end := a_end + 1; end loop; if a_end = a_start then return -1; - -- raise_application_error(-20000, ''Expected number at position '' || a_start); + -- raise_application_error(-20000, 'Expected number at position ' || a_start); end if; if a_end - a_start > 4 then return -1; - -- raise_application_error(-20000, ''Numbers within versions can only be up to 4 digits long''); + -- raise_application_error(-20000, 'Numbers within versions can only be up to 4 digits long'); end if; -- zero-pad and append the number - a_order := a_order || substr(''0000'', 1, 4 - (a_end - a_start)) || - substr(version_name, a_start, a_end - a_start) || ''.''; + a_order := a_order || substr('0000', 1, 4 - (a_end - a_start)) || + substr(version_name, a_start, a_end - a_start) || '.'; a_fields := a_fields + 1; if a_end > length(version_name) then - -- end of string - we''re outta here - if a_seen_letter = ''f'' then - -- append the "final" suffix if there haven''t been any letters + -- end of string - we're outta here + if a_seen_letter = 'f' then + -- append the "final" suffix if there haven't been any letters -- so far (i.e., not development/alpha/beta) - a_order := a_order || repeat(''0000.'',7 - a_fields) || '' 3F.''; + a_order := a_order || repeat('0000.',7 - a_fields) || ' 3F.'; end if; return a_order; end if; - -- what''s the next character? if a period, just skip it + -- what's the next character? if a period, just skip it a_char := substr(version_name, a_end, 1); - if a_char = ''.'' then + if a_char = '.' then else -- if the next character was a letter, append the appropriate characters - if a_char = ''d'' then - a_order := a_order || repeat(''0000.'',7 - a_fields) || '' 0D.''; - else if a_char = ''a'' then - a_order := a_order || repeat(''0000.'',7 - a_fields) || '' 1A.''; - else if a_char = ''b'' then - a_order := a_order || repeat(''0000.'',7 - a_fields) || '' 2B.''; + if a_char = 'd' then + a_order := a_order || repeat('0000.',7 - a_fields) || ' 0D.'; + else if a_char = 'a' then + a_order := a_order || repeat('0000.',7 - a_fields) || ' 1A.'; + else if a_char = 'b' then + a_order := a_order || repeat('0000.',7 - a_fields) || ' 2B.'; end if; end if; end if; - -- can''t have something like 3.3a1b2 - just one letter allowed! - if a_seen_letter = ''t'' then + -- can't have something like 3.3a1b2 - just one letter allowed! + if a_seen_letter = 't' then return -1; - -- raise_application_error(-20000, ''Not allowed to have two letters in version name '''''' - -- || version_name || ''''''''); + -- raise_application_error(-20000, 'Not allowed to have two letters in version name ''' + -- || version_name || ''''); end if; - a_seen_letter := ''t''; + a_seen_letter := 't'; - -- end of string - we''re done! + -- end of string - we're done! if a_end = length(version_name) then return a_order; end if; end if; a_start := a_end + 1; end loop; -end;' language 'plpgsql' immutable; +END; +$$ LANGUAGE plpgsql immutable; -- function version_name_greater -create or replace function apm_package_version__version_name_greater (varchar,varchar) -returns integer as ' -declare - version_name_one alias for $1; - version_name_two alias for $2; + + +-- added +select define_function_args('apm_package_version__version_name_greater','version_name_one,version_name_two'); + +-- +-- procedure apm_package_version__version_name_greater/2 +-- +CREATE OR REPLACE FUNCTION apm_package_version__version_name_greater( + version_name_one varchar, + version_name_two varchar +) RETURNS integer AS $$ +DECLARE a_order_a varchar(250); a_order_b varchar(250); -begin +BEGIN a_order_a := apm_package_version__sortable_version_name(version_name_one); a_order_b := apm_package_version__sortable_version_name(version_name_two); if a_order_a < a_order_b then @@ -2323,37 +2769,46 @@ end if; end if; return 0; -end;' language 'plpgsql' immutable; +END; +$$ LANGUAGE plpgsql immutable; -- function upgrade_p -create or replace function apm_package_version__upgrade_p (varchar,varchar,varchar) -returns integer as ' -declare - upgrade_p__path alias for $1; - upgrade_p__initial_version_name alias for $2; - upgrade_p__final_version_name alias for $3; + + +-- added +select define_function_args('apm_package_version__upgrade_p','path,initial_version_name,final_version_name'); + +-- +-- procedure apm_package_version__upgrade_p/3 +-- +CREATE OR REPLACE FUNCTION apm_package_version__upgrade_p( + upgrade_p__path varchar, + upgrade_p__initial_version_name varchar, + upgrade_p__final_version_name varchar +) RETURNS integer AS $$ +DECLARE v_pos1 integer; v_pos2 integer; v_tmp varchar(1500); v_path varchar(1500); v_version_from apm_package_versions.version_name%TYPE; v_version_to apm_package_versions.version_name%TYPE; -begin +BEGIN -- Set v_path to the tail of the path (the file name). - v_path := substr(upgrade_p__path, instr(upgrade_p__path, ''/'', -1) + 1); + v_path := substr(upgrade_p__path, instr(upgrade_p__path, '/', -1) + 1); -- Remove the extension, if it is .sql. - v_pos1 := position(''.sql'' in v_path); + v_pos1 := position('.sql' in v_path); if v_pos1 > 0 then v_path := substr(v_path, 1, v_pos1 - 1); end if; -- Figure out the from/to version numbers for the individual file. - v_pos1 := instr(v_path, ''-'', -1, 2); - v_pos2 := instr(v_path, ''-'', -1); + v_pos1 := instr(v_path, '-', -1, 2); + v_pos2 := instr(v_path, '-', -1); if v_pos1 = 0 or v_pos2 = 0 then - -- There aren''t two hyphens in the file name. Bail. + -- There aren't two hyphens in the file name. Bail. return 0; end if; @@ -2370,49 +2825,68 @@ -- Invalid version number. -- return 0; -end;' language 'plpgsql' immutable; +END; +$$ LANGUAGE plpgsql immutable; -- procedure upgrade -create or replace function apm_package_version__upgrade (integer) -returns integer as ' -declare - upgrade__version_id alias for $1; -begin + + +-- added +select define_function_args('apm_package_version__upgrade','version_id'); + +-- +-- procedure apm_package_version__upgrade/1 +-- +CREATE OR REPLACE FUNCTION apm_package_version__upgrade( + upgrade__version_id integer +) RETURNS integer AS $$ +DECLARE +BEGIN update apm_package_versions - set enabled_p = ''f'', - installed_p = ''f'' + set enabled_p = 'f', + installed_p = 'f' where package_key = (select package_key from apm_package_versions where version_id = upgrade__version_id); update apm_package_versions - set enabled_p = ''t'', - installed_p = ''t'' + set enabled_p = 't', + installed_p = 't' where version_id = upgrade__version_id; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- show errors -- create or replace package body apm_package_type -- procedure create_type -create or replace function apm_package_type__create_type (varchar,varchar,varchar,varchar,varchar,boolean,boolean,boolean,boolean,varchar,integer) -returns integer as ' -declare - create_type__package_key alias for $1; - create_type__pretty_name alias for $2; - create_type__pretty_plural alias for $3; - create_type__package_uri alias for $4; - create_type__package_type alias for $5; - create_type__initial_install_p alias for $6; - create_type__singleton_p alias for $7; - create_type__implements_subsite_p alias for $8; - create_type__inherit_templates_p alias for $9; - create_type__spec_file_path alias for $10; -- default null - create_type__spec_file_mtime alias for $11; -- default null -begin + + +-- added +select define_function_args('apm_package_type__create_type','package_key,pretty_name,pretty_plural,package_uri,package_type,initial_install_p,singleton_p,implements_subsite_p,inherit_templates_p,spec_file_path;null,spec_file_mtime;null'); + +-- +-- procedure apm_package_type__create_type/11 +-- +CREATE OR REPLACE FUNCTION apm_package_type__create_type( + create_type__package_key varchar, + create_type__pretty_name varchar, + create_type__pretty_plural varchar, + create_type__package_uri varchar, + create_type__package_type varchar, + create_type__initial_install_p boolean, + create_type__singleton_p boolean, + create_type__implements_subsite_p boolean, + create_type__inherit_templates_p boolean, + create_type__spec_file_path varchar, -- default null + create_type__spec_file_mtime integer -- default null + +) RETURNS integer AS $$ +DECLARE +BEGIN insert into apm_package_types (package_key, pretty_name, pretty_plural, package_uri, package_type, spec_file_path, spec_file_mtime, initial_install_p, singleton_p, @@ -2424,25 +2898,35 @@ create_type__implements_subsite_p, create_type__inherit_templates_p); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function update_type -create or replace function apm_package_type__update_type (varchar,varchar,varchar,varchar,varchar,boolean,boolean,boolean,boolean,varchar,integer) -returns varchar as ' -declare - update_type__package_key alias for $1; - update_type__pretty_name alias for $2; -- default null - update_type__pretty_plural alias for $3; -- default null - update_type__package_uri alias for $4; -- default null - update_type__package_type alias for $5; -- default null - update_type__initial_install_p alias for $6; -- default null - update_type__singleton_p alias for $7; -- default null - update_type__implements_subsite_p alias for $8; -- default null - update_type__inherit_templates_p alias for $9; -- default null - update_type__spec_file_path alias for $10; -- default null - update_type__spec_file_mtime alias for $11; -- default null -begin + + +-- added +select define_function_args('apm_package_type__update_type','package_key,pretty_name;null,pretty_plural;null,package_uri;null,package_type;null,initial_install_p;null,singleton_p;null,implements_subsite_p;null,inherit_templates_p;null,spec_file_path;null,spec_file_mtime;null'); + +-- +-- procedure apm_package_type__update_type/11 +-- +CREATE OR REPLACE FUNCTION apm_package_type__update_type( + update_type__package_key varchar, + update_type__pretty_name varchar, -- default null + update_type__pretty_plural varchar, -- default null + update_type__package_uri varchar, -- default null + update_type__package_type varchar, -- default null + update_type__initial_install_p boolean, -- default null + update_type__singleton_p boolean, -- default null + update_type__implements_subsite_p boolean, -- default null + update_type__inherit_templates_p boolean, -- default null + update_type__spec_file_path varchar, -- default null + update_type__spec_file_mtime integer -- default null + +) RETURNS varchar AS $$ +DECLARE +BEGIN UPDATE apm_package_types SET pretty_name = coalesce(update_type__pretty_name, pretty_name), pretty_plural = coalesce(update_type__pretty_plural, pretty_plural), @@ -2458,18 +2942,28 @@ return update_type__package_key; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure drop_type -create or replace function apm_package_type__drop_type (varchar,boolean) -returns integer as ' -declare - drop_type__package_key alias for $1; - drop_type__cascade_p alias for $2; -- default ''f'' + + +-- added +select define_function_args('apm_package_type__drop_type','package_key,cascade_p;f'); + +-- +-- procedure apm_package_type__drop_type/2 +-- +CREATE OR REPLACE FUNCTION apm_package_type__drop_type( + drop_type__package_key varchar, + drop_type__cascade_p boolean -- default 'f' + +) RETURNS integer AS $$ +DECLARE cur_val record; -begin - if drop_type__cascade_p = ''t'' then +BEGIN + if drop_type__cascade_p = 't' then for cur_val in select package_id from apm_packages where package_key = drop_type__package_key @@ -2496,23 +2990,33 @@ where package_key = drop_type__package_key; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function num_parameters -create or replace function apm_package_type__num_parameters (varchar) -returns integer as ' -declare - num_parameters__package_key alias for $1; + + +-- added +select define_function_args('apm_package_type__num_parameters','package_key'); + +-- +-- procedure apm_package_type__num_parameters/1 +-- +CREATE OR REPLACE FUNCTION apm_package_type__num_parameters( + num_parameters__package_key varchar +) RETURNS integer AS $$ +DECLARE v_count integer; -begin +BEGIN select count(*) into v_count from apm_parameters where package_key = num_parameters__package_key; return v_count; -end;' language 'plpgsql' stable; +END; +$$ LANGUAGE plpgsql stable; @@ -2522,26 +3026,35 @@ -- create or replace package body apm_parameter_value -- function new -create or replace function apm_parameter_value__new (integer,integer,integer,varchar) -returns integer as ' -declare - new__value_id alias for $1; -- default null - new__package_id alias for $2; - new__parameter_id alias for $3; - new__attr_value alias for $4; + + +-- added +select define_function_args('apm_parameter_value__new','value_id;null,package_id,parameter_id,attr_value'); + +-- +-- procedure apm_parameter_value__new/4 +-- +CREATE OR REPLACE FUNCTION apm_parameter_value__new( + new__value_id integer, -- default null + new__package_id integer, + new__parameter_id integer, + new__attr_value varchar + +) RETURNS integer AS $$ +DECLARE v_value_id apm_parameter_values.value_id%TYPE; v_title acs_objects.title%TYPE; -begin - select pkg.package_key || '': '' || pkg.instance_name || '' - '' || par.parameter_name into v_title from apm_packages pkg, apm_parameters par where pkg.package_id = new__package_id and par.parameter_id = new__parameter_id; +BEGIN + select pkg.package_key || ': ' || pkg.instance_name || ' - ' || par.parameter_name into v_title from apm_packages pkg, apm_parameters par where pkg.package_id = new__package_id and par.parameter_id = new__parameter_id; v_value_id := acs_object__new( new__value_id, - ''apm_parameter_value'', + 'apm_parameter_value', now(), null, null, null, - ''t'', + 't', v_title, new__package_id ); @@ -2553,37 +3066,57 @@ return v_value_id; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure delete -create or replace function apm_parameter_value__delete (integer) -returns integer as ' -declare - delete__value_id alias for $1; -- default null -begin + + +-- added +select define_function_args('apm_parameter_value__delete','value_id;null'); + +-- +-- procedure apm_parameter_value__delete/1 +-- +CREATE OR REPLACE FUNCTION apm_parameter_value__delete( + delete__value_id integer -- default null + +) RETURNS integer AS $$ +DECLARE +BEGIN delete from apm_parameter_values where value_id = delete__value_id; PERFORM acs_object__delete(delete__value_id); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function new -create or replace function apm_application__new (integer,varchar,varchar,varchar,timestamptz,integer,varchar,integer) -returns integer as ' -declare - application_id alias for $1; -- default null - instance_name alias for $2; -- default null - package_key alias for $3; - object_type alias for $4; -- default ''apm_application'' - creation_date alias for $5; -- default now() - creation_user alias for $6; -- default null - creation_ip alias for $7; -- default null - context_id alias for $8; -- default null + + +-- added +select define_function_args('apm_application__new','application_id;null,instance_name;null,package_key,object_type;apm_application,creation_date;now(),creation_user;null,creation_ip;null,context_id;null'); + +-- +-- procedure apm_application__new/8 +-- +CREATE OR REPLACE FUNCTION apm_application__new( + application_id integer, -- default null + instance_name varchar, -- default null + package_key varchar, + object_type varchar, -- default 'apm_application' + creation_date timestamptz, -- default now() + creation_user integer, -- default null + creation_ip varchar, -- default null + context_id integer -- default null + +) RETURNS integer AS $$ +DECLARE v_application_id integer; -begin +BEGIN v_application_id := apm_package__new ( application_id, instance_name, @@ -2597,43 +3130,62 @@ return v_application_id; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure delete -create or replace function apm_application__delete (integer) -returns integer as ' -declare - delete__application_id alias for $1; -begin + + +-- added +select define_function_args('apm_application__delete','application_id'); + +-- +-- procedure apm_application__delete/1 +-- +CREATE OR REPLACE FUNCTION apm_application__delete( + delete__application_id integer +) RETURNS integer AS $$ +DECLARE +BEGIN delete from apm_applications where application_id = delete__application_id; PERFORM apm_package__delete( delete__application_id ); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- show errors -- create or replace package body apm_service -- function new -create or replace function apm_service__new (integer,varchar,varchar,varchar,timestamptz,integer,varchar,integer) -returns integer as ' -declare - service_id alias for $1; -- default null - instance_name alias for $2; -- default null - package_key alias for $3; - object_type alias for $4; -- default ''apm_service'' - creation_date alias for $5; -- default now() - creation_user alias for $6; -- default null - creation_ip alias for $7; -- default null - context_id alias for $8; -- default null + + +-- added +select define_function_args('apm_service__new','service_id;null,instance_name;null,package_key,object_type;apm_service,creation_date;now(),creation_user;null,creation_ip;null,context_id;null'); + +-- +-- procedure apm_service__new/8 +-- +CREATE OR REPLACE FUNCTION apm_service__new( + service_id integer, -- default null + instance_name varchar, -- default null + package_key varchar, + object_type varchar, -- default 'apm_service' + creation_date timestamptz, -- default now() + creation_user integer, -- default null + creation_ip varchar, -- default null + context_id integer -- default null + +) RETURNS integer AS $$ +DECLARE v_service_id integer; -begin +BEGIN v_service_id := apm_package__new ( service_id, instance_name, @@ -2647,21 +3199,31 @@ return v_service_id; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure delete -create or replace function apm_service__delete (integer) -returns integer as ' -declare - delete__service_id alias for $1; -begin + + +-- added +select define_function_args('apm_service__delete','service_id'); + +-- +-- procedure apm_service__delete/1 +-- +CREATE OR REPLACE FUNCTION apm_service__delete( + delete__service_id integer +) RETURNS integer AS $$ +DECLARE +BEGIN delete from apm_services where service_id = delete__service_id; PERFORM apm_package__delete( delete__service_id ); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; Index: openacs-4/packages/acs-kernel/sql/postgresql/apm-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/postgresql/apm-drop.sql,v diff -u -r1.4 -r1.5 --- openacs-4/packages/acs-kernel/sql/postgresql/apm-drop.sql 23 Mar 2010 21:53:49 -0000 1.4 +++ openacs-4/packages/acs-kernel/sql/postgresql/apm-drop.sql 7 Jul 2011 10:46:02 -0000 1.5 @@ -30,34 +30,35 @@ drop table apm_packages; drop table apm_package_types; -create function inline_0 () returns integer as ' -begin +CREATE OR REPLACE FUNCTION inline_0 () RETURNS integer AS $$ +BEGIN PERFORM acs_object_type__drop_type ( - ''apm_package'', ''f'' + 'apm_package', 'f' ); PERFORM acs_object_type__drop_type ( - ''apm_application'', ''f'' + 'apm_application', 'f' ); PERFORM acs_object_type__drop_type ( - ''apm_service'', ''f'' + 'apm_service', 'f' ); PERFORM acs_object_type__drop_type ( - ''apm_package_version'', ''f'' + 'apm_package_version', 'f' ); PERFORM acs_object_type__drop_type ( - ''apm_parameter_value'', ''f'' + 'apm_parameter_value', 'f' ); PERFORM acs_object_type__drop_type ( - ''apm_parameter'', ''f'' + 'apm_parameter', 'f' ); return null; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select inline_0 (); Index: openacs-4/packages/acs-kernel/sql/postgresql/authentication-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/postgresql/authentication-drop.sql,v diff -u -r1.1 -r1.2 --- openacs-4/packages/acs-kernel/sql/postgresql/authentication-drop.sql 22 Aug 2003 11:38:08 -0000 1.1 +++ openacs-4/packages/acs-kernel/sql/postgresql/authentication-drop.sql 7 Jul 2011 10:46:02 -0000 1.2 @@ -10,20 +10,27 @@ -- @cvs-id $Id$ -- -create function inline_0 () -returns integer as ' -declare + + +-- +-- procedure inline_0/0 +-- +CREATE OR REPLACE FUNCTION inline_0( + +) RETURNS integer AS $$ +DECLARE row record; -begin +BEGIN for row in select authority_id from auth_authorities loop perform authority__del(row.authority_id); end loop; - perform acs_object_type__drop_type(''authority'', ''t''); + perform acs_object_type__drop_type('authority', 't'); return 1; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select inline_0 (); drop function inline_0(); Index: openacs-4/packages/acs-kernel/sql/postgresql/authentication-package-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/postgresql/authentication-package-create.sql,v diff -u -r1.7 -r1.8 --- openacs-4/packages/acs-kernel/sql/postgresql/authentication-package-create.sql 12 Mar 2004 18:48:50 -0000 1.7 +++ openacs-4/packages/acs-kernel/sql/postgresql/authentication-package-create.sql 7 Jul 2011 10:46:02 -0000 1.8 @@ -3,50 +3,42 @@ -- @author Peter Marklund -- @creation-date 2003-08-21 -create or replace function authority__new ( - integer, -- authority_id - varchar, -- object_type - varchar, -- short_name - varchar, -- pretty_name - boolean, -- enabled_p - integer, -- sort_order - integer, -- auth_impl_id - integer, -- pwd_impl_id - varchar, -- forgotten_pwd_url - varchar, -- change_pwd_url - integer, -- register_impl_id - varchar, -- register_url - varchar, -- help_contact_text - integer, -- creation_user - varchar, -- creation_ip - integer -- context_id -) -returns integer as ' -declare - p_authority_id alias for $1; -- default null, - p_object_type alias for $2; -- default ''authority'' - p_short_name alias for $3; - p_pretty_name alias for $4; - p_enabled_p alias for $5; -- default ''t'' - p_sort_order alias for $6; - p_auth_impl_id alias for $7; -- default null - p_pwd_impl_id alias for $8; -- default null - p_forgotten_pwd_url alias for $9; -- default null - p_change_pwd_url alias for $10; -- default null - p_register_impl_id alias for $11; -- default null - p_register_url alias for $12; -- default null - p_help_contact_text alias for $13; -- default null, - p_creation_user alias for $14; -- default null - p_creation_ip alias for $15; -- default null - p_context_id alias for $16; -- default null + + +-- added +select define_function_args('authority__new','authority_id;null,object_type;authority,short_name,pretty_name,enabled_p;t,sort_order,auth_impl_id;null,pwd_impl_id;null,forgotten_pwd_url;null,change_pwd_url;null,register_impl_id;null,register_url;null,help_contact_text;null,creation_user;null,creation_ip;null,context_id;null'); + +-- +-- procedure authority__new/16 +-- +CREATE OR REPLACE FUNCTION authority__new( + p_authority_id integer, -- default null, + p_object_type varchar, -- default 'authority' + p_short_name varchar, + p_pretty_name varchar, + p_enabled_p boolean, -- default 't' + p_sort_order integer, + p_auth_impl_id integer, -- default null + p_pwd_impl_id integer, -- default null + p_forgotten_pwd_url varchar, -- default null + p_change_pwd_url varchar, -- default null + p_register_impl_id integer, -- default null + p_register_url varchar, -- default null + p_help_contact_text varchar, -- default null, + p_creation_user integer, -- default null + p_creation_ip varchar, -- default null + p_context_id integer -- default null + +) RETURNS integer AS $$ +DECLARE v_authority_id integer; v_object_type varchar; v_sort_order integer; -begin +BEGIN if p_object_type is null then - v_object_type := ''authority''; + v_object_type := 'authority'; else v_object_type := p_object_type; end if; @@ -66,7 +58,7 @@ p_creation_user, p_creation_ip, p_context_id, - ''t'', + 't', p_short_name, null ); @@ -81,15 +73,25 @@ p_help_contact_text); return v_authority_id; -end; -' language 'plpgsql'; +END; -create or replace function authority__del (integer) -returns integer as ' -declare - p_authority_id alias for $1; -begin +$$ LANGUAGE plpgsql; + + + +-- added +select define_function_args('authority__del','authority_id'); + +-- +-- procedure authority__del/1 +-- +CREATE OR REPLACE FUNCTION authority__del( + p_authority_id integer +) RETURNS integer AS $$ +DECLARE +BEGIN perform acs_object__delete(p_authority_id); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; Index: openacs-4/packages/acs-kernel/sql/postgresql/community-core-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/postgresql/community-core-create.sql,v diff -u -r1.28 -r1.29 --- openacs-4/packages/acs-kernel/sql/postgresql/community-core-create.sql 2 Jun 2009 00:40:22 -0000 1.28 +++ openacs-4/packages/acs-kernel/sql/postgresql/community-core-create.sql 7 Jul 2011 10:46:02 -0000 1.29 @@ -114,172 +114,179 @@ -- -- * Create constraints for creation_user and modifying_user -create or replace function inline_0 () -returns integer as ' -declare + + +-- +-- procedure inline_0/0 +-- +CREATE OR REPLACE FUNCTION inline_0( + +) RETURNS integer AS $$ +DECLARE attr_id acs_attributes.attribute_id%TYPE; -begin +BEGIN -- -- Party: the supertype of person and organization -- PERFORM acs_object_type__create_type ( - ''party'', - ''#acs-kernel.Party#'', - ''#acs-kernel.Parties#'', - ''acs_object'', - ''parties'', - ''party_id'', - ''party'', - ''f'', + 'party', + '#acs-kernel.Party#', + '#acs-kernel.Parties#', + 'acs_object', + 'parties', + 'party_id', + 'party', + 'f', null, - ''party__name'' + 'party__name' ); attr_id := acs_attribute__create_attribute ( - ''party'', - ''email'', - ''string'', - ''#acs-kernel.Email_Address#'', - ''#acs-kernel.Email_Addresses#'', + 'party', + 'email', + 'string', + '#acs-kernel.Email_Address#', + '#acs-kernel.Email_Addresses#', null, null, null, 0, 1, null, - ''type_specific'', - ''f'' + 'type_specific', + 'f' ); attr_id := acs_attribute__create_attribute ( - ''party'', - ''url'', - ''string'', - ''#acs-kernel.URL#'', - ''#acs-kernel.URLs#'', + 'party', + 'url', + 'string', + '#acs-kernel.URL#', + '#acs-kernel.URLs#', null, null, null, 0, 1, null, - ''type_specific'', - ''f'' + 'type_specific', + 'f' ); -- -- Person: the supertype of user -- attr_id := acs_object_type__create_type ( - ''person'', - ''#acs-kernel.Person#'', - ''#acs-kernel.People#'', - ''party'', - ''persons'', - ''person_id'', - ''person'', - ''f'', + 'person', + '#acs-kernel.Person#', + '#acs-kernel.People#', + 'party', + 'persons', + 'person_id', + 'person', + 'f', null, - ''person__name'' + 'person__name' ); attr_id := acs_attribute__create_attribute ( - ''person'', - ''first_names'', - ''string'', - ''#acs-kernel.First_Names#'', - ''#acs-kernel.First_Names#'', + 'person', + 'first_names', + 'string', + '#acs-kernel.First_Names#', + '#acs-kernel.First_Names#', null, null, null, 0, 1, null, - ''type_specific'', - ''f'' + 'type_specific', + 'f' ); attr_id := acs_attribute__create_attribute ( - ''person'', - ''last_name'', - ''string'', - ''#acs-kernel.Last_Name#'', - ''#acs-kernel.Last_Names#'', + 'person', + 'last_name', + 'string', + '#acs-kernel.Last_Name#', + '#acs-kernel.Last_Names#', null, null, null, 0, 1, null, - ''type_specific'', - ''f'' + 'type_specific', + 'f' ); -- -- User: people who have registered in the system -- attr_id := acs_object_type__create_type ( - ''user'', - ''#acs-kernel.User#'', - ''#acs-kernel.Users#'', - ''person'', - ''users'', - ''user_id'', - ''acs_user'', - ''f'', + 'user', + '#acs-kernel.User#', + '#acs-kernel.Users#', + 'person', + 'users', + 'user_id', + 'acs_user', + 'f', null, null ); attr_id := acs_attribute__create_attribute ( - ''user'', - ''username'', - ''string'', - ''#acs-kernel.Username#'', - ''#acs-kernel.Usernames#'', + 'user', + 'username', + 'string', + '#acs-kernel.Username#', + '#acs-kernel.Usernames#', null, null, null, 0, 1, null, - ''type_specific'', - ''f'' + 'type_specific', + 'f' ); attr_id := acs_attribute__create_attribute ( - ''user'', - ''screen_name'', - ''string'', - ''#acs-kernel.Screen_Name#'', - ''#acs-kernel.Screen_Names#'', + 'user', + 'screen_name', + 'string', + '#acs-kernel.Screen_Name#', + '#acs-kernel.Screen_Names#', null, null, null, 0, 1, null, - ''type_specific'', - ''f'' + 'type_specific', + 'f' ); attr_id := acs_attribute__create_attribute ( - ''person'', - ''bio'', - ''string'', - ''#acs-kernel.Bio#'', - ''#acs-kernel.Bios#'', + 'person', + 'bio', + 'string', + '#acs-kernel.Bio#', + '#acs-kernel.Bios#', null, null, null, 0, 1, null, - ''type_specific'', - ''f'' + 'type_specific', + 'f' ); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select inline_0 (); @@ -318,23 +325,32 @@ -- PARTY PACKAGE -- ------------------- -create or replace function party__new (integer,varchar,timestamptz,integer,varchar,varchar,varchar,integer) -returns integer as ' -declare - new__party_id alias for $1; -- default null - new__object_type alias for $2; -- default ''party'' - new__creation_date alias for $3; -- default now() - new__creation_user alias for $4; -- default null - new__creation_ip alias for $5; -- default null - new__email alias for $6; - new__url alias for $7; -- default null - new__context_id alias for $8; -- default null + + +-- added +select define_function_args('party__new','party_id;null,object_type;party,creation_date;now(),creation_user;null,creation_ip;null,email,url;null,context_id;null'); + +-- +-- procedure party__new/8 +-- +CREATE OR REPLACE FUNCTION party__new( + new__party_id integer, -- default null + new__object_type varchar, -- default 'party' + new__creation_date timestamptz, -- default now() + new__creation_user integer, -- default null + new__creation_ip varchar, -- default null + new__email varchar, + new__url varchar, -- default null + new__context_id integer -- default null + +) RETURNS integer AS $$ +DECLARE v_party_id parties.party_id%TYPE; -begin +BEGIN v_party_id := acs_object__new(new__party_id, new__object_type, new__creation_date, new__creation_user, new__creation_ip, new__context_id, - ''t'', new__email, null); + 't', new__email, null); insert into parties (party_id, email, url) @@ -343,40 +359,68 @@ return v_party_id; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create or replace function party__delete (integer) -returns integer as ' -declare - party_id alias for $1; -begin + + +-- added +select define_function_args('party__delete','party_id'); + +-- +-- procedure party__delete/1 +-- +CREATE OR REPLACE FUNCTION party__delete( + party_id integer +) RETURNS integer AS $$ +DECLARE +BEGIN PERFORM acs_object__delete(party_id); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create or replace function party__name (integer) -returns varchar as ' -declare - party_id alias for $1; -begin + + +-- added +select define_function_args('party__name','party_id'); + +-- +-- procedure party__name/1 +-- +CREATE OR REPLACE FUNCTION party__name( + party_id integer +) RETURNS varchar AS $$ +DECLARE +BEGIN if party_id = -1 then - return ''The Public''; + return 'The Public'; else return null; end if; -end;' language 'plpgsql' immutable strict; +END; +$$ LANGUAGE plpgsql immutable strict; -create or replace function party__email (integer) -returns varchar as ' -declare - email__party_id alias for $1; -begin + +-- added +select define_function_args('party__email','party_id'); + +-- +-- procedure party__email/1 +-- +CREATE OR REPLACE FUNCTION party__email( + email__party_id integer +) RETURNS varchar AS $$ +DECLARE +BEGIN + return email from parties where party_id = email__party_id; -end;' language 'plpgsql' stable strict; +END; +$$ LANGUAGE plpgsql stable strict; -- show errors @@ -437,29 +481,39 @@ -- create or replace package body person -- function new -select define_function_args('person__new','person_id,object_type;person,creation_date;now(),creation_user,creation_ip,email,url,first_names,last_name,context_id'); -create or replace function person__new (integer,varchar,timestamptz,integer,varchar,varchar,varchar,varchar,varchar,integer) -returns integer as ' -declare - new__person_id alias for $1; -- default null - new__object_type alias for $2; -- default ''person'' - new__creation_date alias for $3; -- default now() - new__creation_user alias for $4; -- default null - new__creation_ip alias for $5; -- default null - new__email alias for $6; - new__url alias for $7; -- default null - new__first_names alias for $8; - new__last_name alias for $9; - new__context_id alias for $10; -- default null + +-- old define_function_args('person__new','person_id,object_type;person,creation_date;now(),creation_user,creation_ip,email,url,first_names,last_name,context_id') +-- new +select define_function_args('person__new','person_id;null,object_type;person,creation_date;now(),creation_user;null,creation_ip;null,email,url;null,first_names,last_name,context_id;null'); + + + +-- +-- procedure person__new/10 +-- +CREATE OR REPLACE FUNCTION person__new( + new__person_id integer, -- default null + new__object_type varchar, -- default 'person' + new__creation_date timestamptz, -- default now() -- default 'now()' + new__creation_user integer, -- default null + new__creation_ip varchar, -- default null + new__email varchar, + new__url varchar, -- default null + new__first_names varchar, + new__last_name varchar, + new__context_id integer -- default null + +) RETURNS integer AS $$ +DECLARE v_person_id persons.person_id%TYPE; -begin +BEGIN v_person_id := party__new(new__person_id, new__object_type, new__creation_date, new__creation_user, new__creation_ip, new__email, new__url, new__context_id); update acs_objects - set title = new__first_names || '' '' || new__last_name + set title = new__first_names || ' ' || new__last_name where object_id = v_person_id; insert into persons @@ -469,62 +523,99 @@ return v_person_id; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure delete -create or replace function person__delete (integer) -returns integer as ' -declare - delete__person_id alias for $1; -begin + + +-- added +select define_function_args('person__delete','person_id'); + +-- +-- procedure person__delete/1 +-- +CREATE OR REPLACE FUNCTION person__delete( + delete__person_id integer +) RETURNS integer AS $$ +DECLARE +BEGIN delete from persons where person_id = delete__person_id; PERFORM party__delete(delete__person_id); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function name -create or replace function person__name (integer) -returns varchar as ' -declare - name__person_id alias for $1; -begin - return first_names || '' '' || last_name + +-- added +select define_function_args('person__name','person_id'); + +-- +-- procedure person__name/1 +-- +CREATE OR REPLACE FUNCTION person__name( + name__person_id integer +) RETURNS varchar AS $$ +DECLARE +BEGIN + + return first_names || ' ' || last_name from persons where person_id = name__person_id; -end;' language 'plpgsql' stable strict; +END; +$$ LANGUAGE plpgsql stable strict; -- function first_names -create or replace function person__first_names (integer) -returns varchar as ' -declare - first_names__person_id alias for $1; -begin + + +-- added +select define_function_args('person__first_names','person_id'); + +-- +-- procedure person__first_names/1 +-- +CREATE OR REPLACE FUNCTION person__first_names( + first_names__person_id integer +) RETURNS varchar AS $$ +DECLARE +BEGIN return first_names from persons where person_id = first_names__person_id; -end;' language 'plpgsql' stable strict; +END; +$$ LANGUAGE plpgsql stable strict; -- function last_name -create or replace function person__last_name (integer) -returns varchar as ' -declare - last_name__person_id alias for $1; -begin + + +-- added +select define_function_args('person__last_name','person_id'); + +-- +-- procedure person__last_name/1 +-- +CREATE OR REPLACE FUNCTION person__last_name( + last_name__person_id integer +) RETURNS varchar AS $$ +DECLARE +BEGIN return last_name from persons where person_id = last_name__person_id; -end;' language 'plpgsql' stable strict; +END; +$$ LANGUAGE plpgsql stable strict; -- show errors @@ -580,16 +671,16 @@ timezone varchar(100) ); -create or replace function inline_1 () -returns integer as ' -begin +CREATE OR REPLACE FUNCTION inline_1 () RETURNS integer AS $$ +BEGIN insert into acs_object_type_tables (object_type, table_name, id_column) values - (''user'', ''user_preferences'', ''user_id''); + ('user', 'user_preferences', 'user_id'); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select inline_1 (); @@ -685,52 +776,44 @@ select define_function_args('user__new','user_id,object_type;user,creation_date;now(),creation_user,creation_ip,authority_id,username,email,url,first_names,last_name,password,salt,screen_name,email_verified_p;t,context_id'); -create or replace function acs_user__new ( - integer, -- user_id - varchar, -- object_type - timestamptz, -- creation_date - integer, -- creation_user - varchar, -- creation_ip - integer, -- authority_id; default 'local' - varchar, -- username - varchar, -- email - varchar, -- url - varchar, -- first_names - varchar, -- last_name - char, -- password - char, -- salt - varchar, -- screen_name - boolean, -- email_verified_p - integer -- context_id -) -returns integer as ' -declare - p_user_id alias for $1; -- default null - p_object_type alias for $2; -- default ''user'' - p_creation_date alias for $3; -- default now() - p_creation_user alias for $4; -- default null - p_creation_ip alias for $5; -- default null - p_authority_id alias for $6; -- defaults to local authority - p_username alias for $7; -- - p_email alias for $8; - p_url alias for $9; -- default null - p_first_names alias for $10; - p_last_name alias for $11; - p_password alias for $12; - p_salt alias for $13; - p_screen_name alias for $14; -- default null - p_email_verified_p alias for $15; -- default ''t'' - p_context_id alias for $16; -- default null + + +-- added +select define_function_args('acs_user__new','user_id;null,object_type;user,creation_date;now(),creation_user;null,creation_ip;null,authority_id,username,email,url;null,first_names,last_name,password,salt,screen_name;null,email_verified_p;t,context_id;null'); + +-- +-- procedure acs_user__new/16 +-- +CREATE OR REPLACE FUNCTION acs_user__new( + p_user_id integer, -- default null + p_object_type varchar, -- default 'user' + p_creation_date timestamptz, -- default now() + p_creation_user integer, -- default null + p_creation_ip varchar, -- default null + p_authority_id integer, -- defaults to local authority + p_username varchar, + p_email varchar, + p_url varchar, -- default null + p_first_names varchar, + p_last_name varchar, + p_password char, + p_salt char, + p_screen_name varchar, -- default null + p_email_verified_p boolean, -- default 't' + p_context_id integer -- default null + +) RETURNS integer AS $$ +DECLARE v_user_id users.user_id%TYPE; v_authority_id auth_authorities.authority_id%TYPE; v_person_exists varchar; -begin +BEGIN v_user_id := p_user_id; - select case when count(*) = 0 then ''f'' else ''t'' end into v_person_exists + select case when count(*) = 0 then 'f' else 't' end into v_person_exists from persons where person_id = v_user_id; - if v_person_exists = ''f'' then + if v_person_exists = 'f' then v_user_id := person__new( v_user_id, p_object_type, @@ -744,15 +827,15 @@ p_context_id ); else - update acs_objects set object_type = ''user'' where object_id = v_user_id; + update acs_objects set object_type = 'user' where object_id = v_user_id; end if; -- default to local authority if p_authority_id is null then select authority_id into v_authority_id from auth_authorities - where short_name = ''local''; + where short_name = 'local'; else v_authority_id := p_authority_id; end if; @@ -769,20 +852,26 @@ return v_user_id; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create or replace function acs_user__new(varchar,varchar,varchar,char,char) -returns integer as ' -declare - email alias for $1; - fname alias for $2; - lname alias for $3; - pword alias for $4; - salt alias for $5; -begin + + +-- +-- procedure acs_user__new/5 +-- +CREATE OR REPLACE FUNCTION acs_user__new( + email varchar, + fname varchar, + lname varchar, + pword char, + salt char +) RETURNS integer AS $$ +DECLARE +BEGIN return acs_user__new(null, - ''user'', + 'user', now(), null, null, @@ -795,64 +884,100 @@ null, null, null, - ''t'', + 't', null ); -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function receives_alerts_p -create or replace function acs_user__receives_alerts_p (integer) -returns boolean as ' -declare - receives_alerts_p__user_id alias for $1; + + +-- added +select define_function_args('acs_user__receives_alerts_p','user_id'); + +-- +-- procedure acs_user__receives_alerts_p/1 +-- +CREATE OR REPLACE FUNCTION acs_user__receives_alerts_p( + receives_alerts_p__user_id integer +) RETURNS boolean AS $$ +DECLARE counter boolean; -begin - select case when count(*) = 0 then ''f'' else ''t'' end into counter +BEGIN + select case when count(*) = 0 then 'f' else 't' end into counter from users where no_alerts_until >= now() and user_id = receives_alerts_p__user_id; return counter; -end;' language 'plpgsql' stable; +END; +$$ LANGUAGE plpgsql stable; -- procedure approve_email -create or replace function acs_user__approve_email (integer) -returns integer as ' -declare - approve_email__user_id alias for $1; -begin + + +-- added +select define_function_args('acs_user__approve_email','user_id'); + +-- +-- procedure acs_user__approve_email/1 +-- +CREATE OR REPLACE FUNCTION acs_user__approve_email( + approve_email__user_id integer +) RETURNS integer AS $$ +DECLARE +BEGIN update users - set email_verified_p = ''t'' + set email_verified_p = 't' where user_id = approve_email__user_id; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure unapprove_email -create or replace function acs_user__unapprove_email (integer) -returns integer as ' -declare - unapprove_email__user_id alias for $1; -begin + + +-- added +select define_function_args('acs_user__unapprove_email','user_id'); + +-- +-- procedure acs_user__unapprove_email/1 +-- +CREATE OR REPLACE FUNCTION acs_user__unapprove_email( + unapprove_email__user_id integer +) RETURNS integer AS $$ +DECLARE +BEGIN update users - set email_verified_p = ''f'' + set email_verified_p = 'f' where user_id = unapprove_email__user_id; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure delete -create or replace function acs_user__delete (integer) -returns integer as ' -declare - delete__user_id alias for $1; -begin + + +-- added +select define_function_args('acs_user__delete','user_id'); + +-- +-- procedure acs_user__delete/1 +-- +CREATE OR REPLACE FUNCTION acs_user__delete( + delete__user_id integer +) RETURNS integer AS $$ +DECLARE +BEGIN delete from user_preferences where user_id = delete__user_id; @@ -862,7 +987,8 @@ PERFORM person__delete(delete__user_id); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; Index: openacs-4/packages/acs-kernel/sql/postgresql/groups-body-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/postgresql/groups-body-create.sql,v diff -u -r1.32 -r1.33 --- openacs-4/packages/acs-kernel/sql/postgresql/groups-body-create.sql 10 Mar 2010 00:44:03 -0000 1.32 +++ openacs-4/packages/acs-kernel/sql/postgresql/groups-body-create.sql 7 Jul 2011 10:46:02 -0000 1.33 @@ -26,19 +26,26 @@ drop trigger membership_rels_in_tr on membership_rels; drop function membership_rels_in_tr (); -create or replace function membership_rels_in_tr () returns trigger as ' -declare + + +-- +-- procedure membership_rels_in_tr/0 +-- +CREATE OR REPLACE FUNCTION membership_rels_in_tr( + +) RETURNS trigger AS $$ +DECLARE v_object_id_one acs_rels.object_id_one%TYPE; v_object_id_two acs_rels.object_id_two%TYPE; v_rel_type acs_rels.rel_type%TYPE; v_error text; map record; -begin +BEGIN -- First check if added this relation violated any relational constraints v_error := rel_constraint__violation(new.rel_id); if v_error is not null then - raise EXCEPTION ''-20000: %'', v_error; + raise EXCEPTION '-20000: %', v_error; end if; select object_id_one, object_id_two, rel_type @@ -52,9 +59,9 @@ rel_type, ancestor_rel_type) values (v_object_id_one, v_object_id_two, new.rel_id, v_object_id_one, - v_rel_type, ''membership_rel''); + v_rel_type, 'membership_rel'); - if new.member_state = ''approved'' then + if new.member_state = 'approved' then perform party_approved_member__add(v_object_id_one, v_object_id_two, new.rel_id, v_rel_type); end if; @@ -70,25 +77,33 @@ rel_type, ancestor_rel_type) values (map.group_id, v_object_id_two, new.rel_id, v_object_id_one, - v_rel_type, ''membership_rel''); + v_rel_type, 'membership_rel'); - if new.member_state = ''approved'' then + if new.member_state = 'approved' then perform party_approved_member__add(map.group_id, v_object_id_two, new.rel_id, v_rel_type); end if; end loop; return new; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; create trigger membership_rels_in_tr after insert on membership_rels for each row execute procedure membership_rels_in_tr (); -create or replace function membership_rels_up_tr () returns trigger as ' -declare + + +-- +-- procedure membership_rels_up_tr/0 +-- +CREATE OR REPLACE FUNCTION membership_rels_up_tr( + +) RETURNS trigger AS $$ +DECLARE map record; -begin +BEGIN if new.member_state = old.member_state then return new; @@ -98,7 +113,7 @@ from group_element_index where rel_id = new.rel_id loop - if new.member_state = ''approved'' then + if new.member_state = 'approved' then perform party_approved_member__add(map.group_id, map.element_id, new.rel_id, map.rel_type); else perform party_approved_member__remove(map.group_id, map.element_id, new.rel_id, map.rel_type); @@ -107,20 +122,28 @@ return new; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; create trigger membership_rels_up_tr before update on membership_rels for each row execute procedure membership_rels_up_tr (); -create or replace function membership_rels_del_tr () returns trigger as ' -declare + + +-- +-- procedure membership_rels_del_tr/0 +-- +CREATE OR REPLACE FUNCTION membership_rels_del_tr( + +) RETURNS trigger AS $$ +DECLARE v_error text; map record; -begin +BEGIN -- First check if removing this relation would violate any relational constraints v_error := rel_constraint__violation_if_removed(old.rel_id); if v_error is not null then - raise EXCEPTION ''-20000: %'', v_error; + raise EXCEPTION '-20000: %', v_error; end if; for map in select group_id, element_id, rel_type @@ -135,28 +158,36 @@ return old; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; create trigger membership_rels_del_tr before delete on membership_rels for each row execute procedure membership_rels_del_tr (); drop trigger composition_rels_in_tr on composition_rels; drop function composition_rels_in_tr (); -create or replace function composition_rels_in_tr () returns trigger as ' -declare + + +-- +-- procedure composition_rels_in_tr/0 +-- +CREATE OR REPLACE FUNCTION composition_rels_in_tr( + +) RETURNS trigger AS $$ +DECLARE v_object_id_one acs_rels.object_id_one%TYPE; v_object_id_two acs_rels.object_id_two%TYPE; v_rel_type acs_rels.rel_type%TYPE; v_error text; map record; -begin +BEGIN -- First check if added this relation violated any relational constraints v_error := rel_constraint__violation(new.rel_id); if v_error is not null then - raise EXCEPTION ''-20000: %'', v_error; + raise EXCEPTION '-20000: %', v_error; end if; select object_id_one, object_id_two, rel_type @@ -170,7 +201,7 @@ rel_type, ancestor_rel_type) values (v_object_id_one, v_object_id_two, new.rel_id, v_object_id_one, - v_rel_type, ''composition_rel''); + v_rel_type, 'composition_rel'); -- Add to the denormalized party_approved_member_map @@ -212,7 +243,7 @@ rel_type, ancestor_rel_type) values (map.group_id, v_object_id_two, new.rel_id, v_object_id_one, - v_rel_type, ''composition_rel''); + v_rel_type, 'composition_rel'); -- Add to party_approved_member_map @@ -244,7 +275,8 @@ return new; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; create trigger composition_rels_in_tr after insert on composition_rels for each row execute procedure composition_rels_in_tr (); @@ -253,18 +285,25 @@ -- TO DO: See if this can be optimized now that the member and component -- mapping tables have been combined -- -create or replace function composition_rels_del_tr () returns trigger as ' -declare + + +-- +-- procedure composition_rels_del_tr/0 +-- +CREATE OR REPLACE FUNCTION composition_rels_del_tr( + +) RETURNS trigger AS $$ +DECLARE v_object_id_one acs_rels.object_id_one%TYPE; v_object_id_two acs_rels.object_id_two%TYPE; n_rows integer; v_error text; map record; -begin +BEGIN -- First check if removing this relation would violate any relational constraints v_error := rel_constraint__violation_if_removed(old.rel_id); if v_error is not null then - raise EXCEPTION ''-20000: %'', v_error; + raise EXCEPTION '-20000: %', v_error; end if; select object_id_one, object_id_two into v_object_id_one, v_object_id_two @@ -294,7 +333,7 @@ delete from group_element_index where group_id = map.group_id and container_id = map.component_id - and ancestor_rel_type = ''membership_rel''; + and ancestor_rel_type = 'membership_rel'; end if; end loop; @@ -314,7 +353,7 @@ union select v_object_id_two from dual) - and group_contains_p(group_id, component_id, rel_id) = ''f'' + and group_contains_p(group_id, component_id, rel_id) = 'f' LOOP delete from group_element_index @@ -338,13 +377,14 @@ delete from group_element_index where group_id = map.group_id and container_id = map.component_id - and ancestor_rel_type = ''membership_rel''; + and ancestor_rel_type = 'membership_rel'; end loop; return old; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; create trigger composition_rels_del_tr before delete on composition_rels for each row execute procedure composition_rels_del_tr (); @@ -355,19 +395,29 @@ -- create or replace package body composition_rel -- function new -select define_function_args('composition_rel__new','rel_id,rel_type;composition_rel,object_id_one,object_id_two,creation_user,creation_ip'); -create or replace function composition_rel__new (integer,varchar,integer,integer,integer,varchar) -returns integer as ' -declare - new__rel_id alias for $1; -- default null - rel_type alias for $2; -- default ''composition_rel'' - object_id_one alias for $3; - object_id_two alias for $4; - creation_user alias for $5; -- default null - creation_ip alias for $6; -- default null +-- old define_function_args('composition_rel__new','rel_id,rel_type;composition_rel,object_id_one,object_id_two,creation_user,creation_ip') +-- new +select define_function_args('composition_rel__new','rel_id;null,rel_type;composition_rel,object_id_one,object_id_two,creation_user;null,creation_ip;null'); + + + + +-- +-- procedure composition_rel__new/6 +-- +CREATE OR REPLACE FUNCTION composition_rel__new( + new__rel_id integer, -- default null + rel_type varchar, -- default 'composition_rel' + object_id_one integer, + object_id_two integer, + creation_user integer, -- default null + creation_ip varchar -- default null + +) RETURNS integer AS $$ +DECLARE v_rel_id integer; -begin +BEGIN v_rel_id := acs_rel__new ( new__rel_id, rel_type, @@ -385,75 +435,111 @@ return v_rel_id; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function new -create or replace function composition_rel__new (integer,integer) -returns integer as ' -declare - object_id_one alias for $1; - object_id_two alias for $2; -begin + + +-- +-- procedure composition_rel__new/2 +-- +CREATE OR REPLACE FUNCTION composition_rel__new( + object_id_one integer, + object_id_two integer +) RETURNS integer AS $$ +-- +-- composition_rel__new/2 maybe obsolete, when we define proper defaults for /6 +-- +DECLARE +BEGIN return composition_rel__new(null, - ''composition_rel'', + 'composition_rel', object_id_one, object_id_two, null, null); -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure delete -create or replace function composition_rel__delete (integer) -returns integer as ' -declare - rel_id alias for $1; -begin + + +-- added +select define_function_args('composition_rel__delete','rel_id'); + +-- +-- procedure composition_rel__delete/1 +-- +CREATE OR REPLACE FUNCTION composition_rel__delete( + rel_id integer +) RETURNS integer AS $$ +DECLARE +BEGIN PERFORM acs_rel__delete(rel_id); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function check_path_exists_p -create or replace function composition_rel__check_path_exists_p (integer,integer) -returns boolean as ' -declare - component_id alias for $1; - container_id alias for $2; + + +-- added +select define_function_args('composition_rel__check_path_exists_p','component_id,container_id'); + +-- +-- procedure composition_rel__check_path_exists_p/2 +-- +CREATE OR REPLACE FUNCTION composition_rel__check_path_exists_p( + component_id integer, + container_id integer +) RETURNS boolean AS $$ +DECLARE row record; -begin +BEGIN if component_id = container_id then - return ''t''; + return 't'; end if; for row in select r.object_id_one as parent_id from acs_rels r, composition_rels c where r.rel_id = c.rel_id and r.object_id_two = component_id LOOP - if composition_rel__check_path_exists_p(row.parent_id, container_id) = ''t'' then - return ''t''; + if composition_rel__check_path_exists_p(row.parent_id, container_id) = 't' then + return 't'; end if; end loop; - return ''f''; + return 'f'; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function check_index -create or replace function composition_rel__check_index (integer,integer) -returns boolean as ' -declare - check_index__component_id alias for $1; - check_index__container_id alias for $2; + + +-- added +select define_function_args('composition_rel__check_index','component_id,container_id'); + +-- +-- procedure composition_rel__check_index/2 +-- +CREATE OR REPLACE FUNCTION composition_rel__check_index( + check_index__component_id integer, + check_index__container_id integer +) RETURNS boolean AS $$ +DECLARE result boolean; n_rows integer; dc record; r1 record; r2 record; -begin - result := ''t''; +BEGIN + result := 't'; -- Loop through all the direct containers (DC) of COMPONENT_ID -- that are also contained by CONTAINER_ID and verify that the @@ -466,20 +552,20 @@ LOOP if composition_rel__check_path_exists_p(dc.container_id, - check_index__container_id) = ''t'' then + check_index__container_id) = 't' then select case when count(*) = 0 then 0 else 1 end into n_rows from group_component_index where group_id = check_index__container_id and component_id = check_index__component_id and rel_id = dc.rel_id; if n_rows = 0 then - result := ''f''; - PERFORM acs_log__error(''composition_rel.check_representation'', - ''Row missing from group_component_index for ('' || - ''group_id = '' || check_index__container_id || '', '' || - ''component_id = '' || check_index__component_id || '', '' || - ''rel_id = '' || dc.rel_id || '')''); + result := 'f'; + PERFORM acs_log__error('composition_rel.check_representation', + 'Row missing from group_component_index for (' || + 'group_id = ' || check_index__container_id || ', ' || + 'component_id = ' || check_index__component_id || ', ' || + 'rel_id = ' || dc.rel_id || ')'); end if; end if; @@ -507,31 +593,40 @@ LOOP if (r1.container_id != check_index__container_id or r2.component_id != check_index__component_id) and - composition_rel__check_index(r2.component_id, r1.container_id) = ''f'' then - result := ''f''; + composition_rel__check_index(r2.component_id, r1.container_id) = 'f' then + result := 'f'; end if; end loop; end loop; return result; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function check_representation -create or replace function composition_rel__check_representation (integer) -returns boolean as ' -declare - check_representation__rel_id alias for $1; + + +-- added +select define_function_args('composition_rel__check_representation','rel_id'); + +-- +-- procedure composition_rel__check_representation/1 +-- +CREATE OR REPLACE FUNCTION composition_rel__check_representation( + check_representation__rel_id integer +) RETURNS boolean AS $$ +DECLARE container_id groups.group_id%TYPE; component_id groups.group_id%TYPE; result boolean; row record; -begin - result := ''t''; +BEGIN + result := 't'; - if acs_object__check_representation(check_representation__rel_id) = ''f'' then - result := ''f''; + if acs_object__check_representation(check_representation__rel_id) = 'f' then + result := 'f'; end if; select object_id_one, object_id_two @@ -540,51 +635,62 @@ where rel_id = check_representation__rel_id; -- First let us check that the index has all the rows it should. - if composition_rel__check_index(component_id, container_id) = ''f'' then - result := ''f''; + if composition_rel__check_index(component_id, container_id) = 'f' then + result := 'f'; end if; - -- Now let us check that the index doesn''t have any extraneous rows + -- Now let us check that the index doesn't have any extraneous rows -- relating to this relation. for row in select * from group_component_index where rel_id = check_representation__rel_id LOOP - if composition_rel__check_path_exists_p(row.component_id, row.group_id) = ''f'' then - result := ''f''; - PERFORM acs_log__error(''composition_rel.check_representation'', - ''Extraneous row in group_component_index: '' || - ''group_id = '' || row.group_id || '', '' || - ''component_id = '' || row.component_id || '', '' || - ''rel_id = '' || row.rel_id || '', '' || - ''container_id = '' || row.container_id || ''.''); + if composition_rel__check_path_exists_p(row.component_id, row.group_id) = 'f' then + result := 'f'; + PERFORM acs_log__error('composition_rel.check_representation', + 'Extraneous row in group_component_index: ' || + 'group_id = ' || row.group_id || ', ' || + 'component_id = ' || row.component_id || ', ' || + 'rel_id = ' || row.rel_id || ', ' || + 'container_id = ' || row.container_id || '.'); end if; end loop; return result; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- show errors -- create or replace package body membership_rel -- function new -select define_function_args('membership_rel__new','rel_id,rel_type;membership_rel,object_id_one,object_id_two,member_state;approved,creation_user,creation_ip'); -create or replace function membership_rel__new (integer,varchar,integer,integer,varchar,integer,varchar) -returns integer as ' -declare - new__rel_id alias for $1; -- default null - rel_type alias for $2; -- default ''membership_rel'' - object_id_one alias for $3; - object_id_two alias for $4; - new__member_state alias for $5; -- default ''approved'' - creation_user alias for $6; -- default null - creation_ip alias for $7; -- default null +-- old define_function_args('membership_rel__new','rel_id,rel_type;membership_rel,object_id_one,object_id_two,member_state;approved,creation_user,creation_ip') +-- new +select define_function_args('membership_rel__new','rel_id;null,rel_type;membership_rel,object_id_one,object_id_two,member_state;approved,creation_user;null,creation_ip;null'); + + + + +-- +-- procedure membership_rel__new/7 +-- +CREATE OR REPLACE FUNCTION membership_rel__new( + new__rel_id integer, -- default null + rel_type varchar, -- default 'membership_rel' + object_id_one integer, + object_id_two integer, + new__member_state varchar, -- default 'approved' + creation_user integer, -- default null + creation_ip varchar -- default null + +) RETURNS integer AS $$ +DECLARE v_rel_id integer; -begin +BEGIN v_rel_id := acs_rel__new ( new__rel_id, rel_type, @@ -602,129 +708,210 @@ return v_rel_id; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function new -create or replace function membership_rel__new (integer,integer) -returns integer as ' -declare - object_id_one alias for $1; - object_id_two alias for $2; -begin + + +-- +-- procedure membership_rel__new/2 +-- +CREATE OR REPLACE FUNCTION membership_rel__new( + object_id_one integer, + object_id_two integer +) RETURNS integer AS $$ +-- +-- membership_rel__new/2 maybe obsolete, when we define proper defaults for /7 +-- +DECLARE +BEGIN return membership_rel__new(null, - ''membership_rel'', + 'membership_rel', object_id_one, object_id_two, - ''approved'', + 'approved', null, null); -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure ban -create or replace function membership_rel__ban (integer) -returns integer as ' -declare - ban__rel_id alias for $1; -begin + + +-- added +select define_function_args('membership_rel__ban','rel_id'); + +-- +-- procedure membership_rel__ban/1 +-- +CREATE OR REPLACE FUNCTION membership_rel__ban( + ban__rel_id integer +) RETURNS integer AS $$ +DECLARE +BEGIN update membership_rels - set member_state = ''banned'' + set member_state = 'banned' where rel_id = ban__rel_id; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure approve -create or replace function membership_rel__approve (integer) -returns integer as ' -declare - approve__rel_id alias for $1; -begin + + +-- added +select define_function_args('membership_rel__approve','rel_id'); + +-- +-- procedure membership_rel__approve/1 +-- +CREATE OR REPLACE FUNCTION membership_rel__approve( + approve__rel_id integer +) RETURNS integer AS $$ +DECLARE +BEGIN update membership_rels - set member_state = ''approved'' + set member_state = 'approved' where rel_id = approve__rel_id; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure reject -create or replace function membership_rel__reject (integer) -returns integer as ' -declare - reject__rel_id alias for $1; -begin + + +-- added +select define_function_args('membership_rel__reject','rel_id'); + +-- +-- procedure membership_rel__reject/1 +-- +CREATE OR REPLACE FUNCTION membership_rel__reject( + reject__rel_id integer +) RETURNS integer AS $$ +DECLARE +BEGIN update membership_rels - set member_state = ''rejected'' + set member_state = 'rejected' where rel_id = reject__rel_id; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure unapprove -create or replace function membership_rel__unapprove (integer) -returns integer as ' -declare - unapprove__rel_id alias for $1; -begin + + +-- added +select define_function_args('membership_rel__unapprove','rel_id'); + +-- +-- procedure membership_rel__unapprove/1 +-- +CREATE OR REPLACE FUNCTION membership_rel__unapprove( + unapprove__rel_id integer +) RETURNS integer AS $$ +DECLARE +BEGIN update membership_rels - set member_state = ''needs approval'' + set member_state = 'needs approval' where rel_id = unapprove__rel_id; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure deleted -create or replace function membership_rel__deleted (integer) -returns integer as ' -declare - deleted__rel_id alias for $1; -begin + + +-- added +select define_function_args('membership_rel__deleted','rel_id'); + +-- +-- procedure membership_rel__deleted/1 +-- +CREATE OR REPLACE FUNCTION membership_rel__deleted( + deleted__rel_id integer +) RETURNS integer AS $$ +DECLARE +BEGIN update membership_rels - set member_state = ''deleted'' + set member_state = 'deleted' where rel_id = deleted__rel_id; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure delete -create or replace function membership_rel__delete (integer) -returns integer as ' -declare - rel_id alias for $1; -begin + + +-- added +select define_function_args('membership_rel__delete','rel_id'); + +-- +-- procedure membership_rel__delete/1 +-- +CREATE OR REPLACE FUNCTION membership_rel__delete( + rel_id integer +) RETURNS integer AS $$ +DECLARE +BEGIN PERFORM acs_rel__delete(rel_id); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure merge -create or replace function membership_rel__merge (integer) -returns integer as ' -declare - merge__rel_id alias for $1; -begin + + +-- added +select define_function_args('membership_rel__merge','rel_id'); + +-- +-- procedure membership_rel__merge/1 +-- +CREATE OR REPLACE FUNCTION membership_rel__merge( + merge__rel_id integer +) RETURNS integer AS $$ +DECLARE +BEGIN update membership_rels - set member_state = ''merged'' + set member_state = 'merged' where rel_id = merge__rel_id; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function check_index -create or replace function membership_rel__check_index (integer,integer,integer) -returns boolean as ' -declare - check_index__group_id alias for $1; - check_index__member_id alias for $2; - check_index__container_id alias for $3; + + +-- added +select define_function_args('membership_rel__check_index','group_id,member_id,container_id'); + +-- +-- procedure membership_rel__check_index/3 +-- +CREATE OR REPLACE FUNCTION membership_rel__check_index( + check_index__group_id integer, + check_index__member_id integer, + check_index__container_id integer +) RETURNS boolean AS $$ +DECLARE result boolean; n_rows integer; row record; -begin +BEGIN select count(*) into n_rows from group_element_index @@ -733,43 +920,52 @@ and container_id = check_index__container_id; if n_rows = 0 then - result := ''f''; - PERFORM acs_log__error(''membership_rel.check_representation'', - ''Row missing from group_element_index: '' || - ''group_id = '' || check_index__group_id || '', '' || - ''member_id = '' || check_index__member_id || '', '' || - ''container_id = '' || check_index__container_id || ''.''); + result := 'f'; + PERFORM acs_log__error('membership_rel.check_representation', + 'Row missing from group_element_index: ' || + 'group_id = ' || check_index__group_id || ', ' || + 'member_id = ' || check_index__member_id || ', ' || + 'container_id = ' || check_index__container_id || '.'); end if; for row in select r.object_id_one as container_id from acs_rels r, composition_rels c where r.rel_id = c.rel_id and r.object_id_two = check_index__group_id LOOP - if membership_rel__check_index(row.container_id, check_index__member_id, check_index__container_id) = ''f'' then - result := ''f''; + if membership_rel__check_index(row.container_id, check_index__member_id, check_index__container_id) = 'f' then + result := 'f'; end if; end loop; return result; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function check_representation -create or replace function membership_rel__check_representation (integer) -returns boolean as ' -declare - check_representation__rel_id alias for $1; + + +-- added +select define_function_args('membership_rel__check_representation','rel_id'); + +-- +-- procedure membership_rel__check_representation/1 +-- +CREATE OR REPLACE FUNCTION membership_rel__check_representation( + check_representation__rel_id integer +) RETURNS boolean AS $$ +DECLARE group_id groups.group_id%TYPE; member_id parties.party_id%TYPE; result boolean; row record; -begin - result := ''t''; +BEGIN + result := 't'; - if acs_object__check_representation(check_representation__rel_id) = ''f'' then - result := ''f''; + if acs_object__check_representation(check_representation__rel_id) = 'f' then + result := 'f'; end if; select r.object_id_one, r.object_id_two @@ -778,51 +974,62 @@ where r.rel_id = m.rel_id and m.rel_id = check_representation__rel_id; - if membership_rel__check_index(group_id, member_id, group_id) = ''f'' then - result := ''f''; + if membership_rel__check_index(group_id, member_id, group_id) = 'f' then + result := 'f'; end if; for row in select * from group_member_index where rel_id = check_representation__rel_id LOOP if composition_rel__check_path_exists_p(row.container_id, - row.group_id) = ''f'' then - result := ''f''; - PERFORM acs_log__error(''membership_rel.check_representation'', - ''Extra row in group_member_index: '' || - ''group_id = '' || row.group_id || '', '' || - ''member_id = '' || row.member_id || '', '' || - ''container_id = '' || row.container_id || ''.''); + row.group_id) = 'f' then + result := 'f'; + PERFORM acs_log__error('membership_rel.check_representation', + 'Extra row in group_member_index: ' || + 'group_id = ' || row.group_id || ', ' || + 'member_id = ' || row.member_id || ', ' || + 'container_id = ' || row.container_id || '.'); end if; end loop; return result; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- create or replace package body acs_group -- function new -select define_function_args('acs_group__new','group_id,object_type;group,creation_date;now(),creation_user,creation_ip,email,url,group_name,join_policy,context_id'); -create or replace function acs_group__new (integer,varchar,timestamptz,integer,varchar,varchar,varchar,varchar,varchar,integer) -returns integer as ' -declare - new__group_id alias for $1; -- default null - new__object_type alias for $2; -- default ''group'' - new__creation_date alias for $3; -- default now() - new__creation_user alias for $4; -- default null - new__creation_ip alias for $5; -- default null - new__email alias for $6; -- default null - new__url alias for $7; -- default null - new__group_name alias for $8; - new__join_policy alias for $9; -- default null - new__context_id alias for $10; -- default null +-- old define_function_args('acs_group__new','group_id,object_type;group,creation_date;now(),creation_user,creation_ip,email,url,group_name,join_policy,context_id') +-- new +select define_function_args('acs_group__new','group_id;null,object_type;group,creation_date;now(),creation_user;null,creation_ip;null,email;null,url;null,group_name,join_policy;null,context_id;null'); + + + + +-- +-- procedure acs_group__new/10 +-- +CREATE OR REPLACE FUNCTION acs_group__new( + new__group_id integer, -- default null + new__object_type varchar, -- default 'group' + new__creation_date timestamptz, -- default now() -- default 'now()' + new__creation_user integer, -- default null + new__creation_ip varchar, -- default null + new__email varchar, -- default null + new__url varchar, -- default null + new__group_name varchar, + new__join_policy varchar, -- default null + new__context_id integer -- default null + +) RETURNS integer AS $$ +DECLARE v_group_id groups.group_id%TYPE; v_group_type_exists_p integer; v_join_policy groups.join_policy%TYPE; -begin +BEGIN v_group_id := party__new(new__group_id, new__object_type, new__creation_date, new__creation_user, new__creation_ip, new__email, @@ -831,7 +1038,7 @@ v_join_policy := new__join_policy; -- if join policy was not specified, select the default based on group type - if v_join_policy is null or v_join_policy = '''' then + if v_join_policy is null or v_join_policy = '' then select count(*) into v_group_type_exists_p from group_types where group_type = new__object_type; @@ -841,7 +1048,7 @@ from group_types where group_type = new__object_type; else - v_join_policy := ''open''; + v_join_policy := 'open'; end if; end if; @@ -860,13 +1067,13 @@ -- return more than one row. The sequence hack will only compute -- one nextval value causing the insert to fail ("may" in PG, which -- is actually broken. It should ALWAYS return exactly one value for - -- the view. In PG it may or may not depending on the optimizer''s + -- the view. In PG it may or may not depending on the optimizer's -- mood. PG group seems uninterested in acknowledging the fact that -- this is a bug) insert into group_rels (group_rel_id, group_id, rel_type) - select nextval(''t_acs_object_id_seq''), v_group_id, rels.rel_type + select nextval('t_acs_object_id_seq'), v_group_id, rels.rel_type from ( select distinct g.rel_type from group_type_rels g, @@ -886,15 +1093,25 @@ return v_group_id; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function new -create or replace function acs_group__new (varchar) returns integer as ' -declare - gname alias for $1; -begin + + +-- +-- procedure acs_group__new/1 +-- +CREATE OR REPLACE FUNCTION acs_group__new( + gname varchar +) RETURNS integer AS $$ +-- +-- acs_group__new/1 maybe obsolete, when we define proper defaults for /10 +-- +DECLARE +BEGIN return acs_group__new(null, - ''group'', + 'group', now(), null, null, @@ -903,15 +1120,24 @@ gname, null, null); -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure delete -create or replace function acs_group__delete (integer) -returns integer as ' -declare - delete__group_id alias for $1; + + +-- added +select define_function_args('acs_group__delete','group_id'); + +-- +-- procedure acs_group__delete/1 +-- +CREATE OR REPLACE FUNCTION acs_group__delete( + delete__group_id integer +) RETURNS integer AS $$ +DECLARE row record; -begin +BEGIN -- Delete all the relations of any type to this group for row in select r.rel_id, t.package_name @@ -920,7 +1146,7 @@ and (r.object_id_one = delete__group_id or r.object_id_two = delete__group_id) LOOP - execute ''select '' || row.package_name || ''__delete('' || row.rel_id || '')''; + execute 'select ' || row.package_name || '__delete(' || row.rel_id || ')'; end loop; -- Delete all segments defined for this group @@ -934,32 +1160,50 @@ PERFORM party__delete(delete__group_id); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function name -create or replace function acs_group__name (integer) -returns varchar as ' -declare - name__group_id alias for $1; + + +-- added +select define_function_args('acs_group__name','group_id'); + +-- +-- procedure acs_group__name/1 +-- +CREATE OR REPLACE FUNCTION acs_group__name( + name__group_id integer +) RETURNS varchar AS $$ +DECLARE name__group_name varchar(200); -begin +BEGIN select group_name into name__group_name from groups where group_id = name__group_id; return name__group_name; -end;' language 'plpgsql' stable strict; +END; +$$ LANGUAGE plpgsql stable strict; -create or replace function acs_group__member_p (integer, integer, boolean) -returns boolean as ' -declare - p_party_id alias for $1; - p_group_id alias for $2; - p_cascade_membership alias for $3; -begin + + +-- added +select define_function_args('acs_group__member_p','party_id,group_id,cascade_membership'); + +-- +-- procedure acs_group__member_p/3 +-- +CREATE OR REPLACE FUNCTION acs_group__member_p( + p_party_id integer, + p_group_id integer, + p_cascade_membership boolean +) RETURNS boolean AS $$ +DECLARE +BEGIN if p_cascade_membership then return count(*) > 0 from group_member_map @@ -969,44 +1213,53 @@ return count(*) > 0 from acs_rels rels, all_object_party_privilege_map perm where perm.object_id = rels.rel_id - and perm.privilege = ''read'' - and rels.rel_type = ''membership_rel'' + and perm.privilege = 'read' + and rels.rel_type = 'membership_rel' and rels.object_id_one = p_group_id and rels.object_id_two = p_party_id; end if; -end;' language 'plpgsql' stable; +END; +$$ LANGUAGE plpgsql stable; -- function check_representation -create or replace function acs_group__check_representation (integer) -returns boolean as ' -declare - group_id alias for $1; + + +-- added +select define_function_args('acs_group__check_representation','group_id'); + +-- +-- procedure acs_group__check_representation/1 +-- +CREATE OR REPLACE FUNCTION acs_group__check_representation( + group_id integer +) RETURNS boolean AS $$ +DECLARE res boolean; comp record; memb record; -begin +BEGIN if group_id is null then - --maybe we should just return ''f'' instead? - raise exception ''acs_group__check_representation called with null group_id''; + --maybe we should just return 'f' instead? + raise exception 'acs_group__check_representation called with null group_id'; end if; - res := ''t''; - PERFORM acs_log__notice(''acs_group.check_representation'', - ''Running check_representation on group '' || group_id); + res := 't'; + PERFORM acs_log__notice('acs_group.check_representation', + 'Running check_representation on group ' || group_id); - if acs_object__check_representation(group_id) = ''f'' then - res := ''f''; + if acs_object__check_representation(group_id) = 'f' then + res := 'f'; end if; for comp in select c.rel_id from acs_rels r, composition_rels c where r.rel_id = c.rel_id and r.object_id_one = group_id LOOP - if composition_rel__check_representation(comp.rel_id) = ''f'' then - res := ''f''; + if composition_rel__check_representation(comp.rel_id) = 'f' then + res := 'f'; end if; end loop; @@ -1015,17 +1268,18 @@ where r.rel_id = m.rel_id and r.object_id_one = group_id LOOP - if membership_rel__check_representation(memb.rel_id) = ''f'' then - res := ''f''; + if membership_rel__check_representation(memb.rel_id) = 'f' then + res := 'f'; end if; end loop; - PERFORM acs_log__notice(''acs_group.check_representation'', - ''Done running check_representation on group '' || group_id); + PERFORM acs_log__notice('acs_group.check_representation', + 'Done running check_representation on group ' || group_id); return res; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; @@ -1034,20 +1288,30 @@ -- create or replace package body admin_rel -- function new -select define_function_args('admin_rel__new','rel_id,rel_type;admin_rel,object_id_one,object_id_two,member_state;approved,creation_user,creation_ip'); -create or replace function admin_rel__new (integer,varchar,integer,integer,varchar,integer,varchar) -returns integer as ' -declare - p_rel_id alias for $1; -- default null - p_rel_type alias for $2; -- default ''admin_rel'' - p_object_id_one alias for $3; - p_object_id_two alias for $4; - p_member_state alias for $5; -- default ''approved'' - p_creation_user alias for $6; -- default null - p_creation_ip alias for $7; -- default null +-- old define_function_args('admin_rel__new','rel_id,rel_type;admin_rel,object_id_one,object_id_two,member_state;approved,creation_user,creation_ip') +-- new +select define_function_args('admin_rel__new','rel_id;null,rel_type;admin_rel,object_id_one,object_id_two,member_state;approved,creation_user;null,creation_ip;null'); + + + + +-- +-- procedure admin_rel__new/7 +-- +CREATE OR REPLACE FUNCTION admin_rel__new( + p_rel_id integer, -- default null + p_rel_type varchar, -- default 'admin_rel' + p_object_id_one integer, + p_object_id_two integer, + p_member_state varchar, -- default 'approved' + p_creation_user integer, -- default null + p_creation_ip varchar -- default null + +) RETURNS integer AS $$ +DECLARE v_rel_id integer; -begin +BEGIN v_rel_id := membership_rel__new ( p_rel_id, -- rel_id p_rel_type, -- rel_type @@ -1065,35 +1329,54 @@ return v_rel_id; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function new -create or replace function admin_rel__new (integer,integer) -returns integer as ' -declare - object_id_one alias for $1; - object_id_two alias for $2; -begin + + +-- +-- procedure admin_rel__new/2 +-- +CREATE OR REPLACE FUNCTION admin_rel__new( + object_id_one integer, + object_id_two integer +) RETURNS integer AS $$ +-- +-- admin_rel__new/2 maybe obsolete, when we define proper defaults for /7 +-- +DECLARE +BEGIN return membership_rel__new( null, -- rel_id - ''admin_rel'', -- rel_type + 'admin_rel', -- rel_type object_id_one, -- object_id_one object_id_two, -- object_id_two - ''approved'', -- member_state + 'approved', -- member_state null, -- creation_user null -- creation_ip ); -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure delete -create or replace function admin_rel__delete (integer) -returns integer as ' -declare - rel_id alias for $1; -begin + + +-- added +select define_function_args('admin_rel__delete','rel_id'); + +-- +-- procedure admin_rel__delete/1 +-- +CREATE OR REPLACE FUNCTION admin_rel__delete( + rel_id integer +) RETURNS integer AS $$ +DECLARE +BEGIN PERFORM membership_rel__delete(rel_id); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; Index: openacs-4/packages/acs-kernel/sql/postgresql/groups-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/postgresql/groups-create.sql,v diff -u -r1.27 -r1.28 --- openacs-4/packages/acs-kernel/sql/postgresql/groups-create.sql 10 Mar 2010 00:44:03 -0000 1.27 +++ openacs-4/packages/acs-kernel/sql/postgresql/groups-create.sql 7 Jul 2011 10:46:02 -0000 1.28 @@ -44,63 +44,69 @@ primary key ); -create function inline_0 () -returns integer as ' -declare + + +-- +-- procedure inline_0/0 +-- +CREATE OR REPLACE FUNCTION inline_0( + +) RETURNS integer AS $$ +DECLARE attr_id acs_attributes.attribute_id%TYPE; -begin +BEGIN -- -- Group: a composite party -- attr_id := acs_object_type__create_type ( - ''group'', - ''#acs-kernel.Group#'', - ''#acs-kernel.Groups#'', - ''party'', - ''groups'', - ''group_id'', - ''acs_group'', - ''f'', - ''group_types'', - ''acs_group__name'' + 'group', + '#acs-kernel.Group#', + '#acs-kernel.Groups#', + 'party', + 'groups', + 'group_id', + 'acs_group', + 'f', + 'group_types', + 'acs_group__name' ); attr_id := acs_attribute__create_attribute ( - ''group'', - ''group_name'', - ''string'', - ''#acs-kernel.Group_name#'', - ''#acs-kernel.Group_names#'', + 'group', + 'group_name', + 'string', + '#acs-kernel.Group_name#', + '#acs-kernel.Group_names#', null, null, null, 1, 1, null, - ''type_specific'', - ''f'' + 'type_specific', + 'f' ); -- -- Composition Relationship -- - attr_id := acs_rel_type__create_role (''composite'', ''Composite'', ''Composites''); - attr_id := acs_rel_type__create_role (''component'', ''Component'', ''Components''); + attr_id := acs_rel_type__create_role ('composite', 'Composite', 'Composites'); + attr_id := acs_rel_type__create_role ('component', 'Component', 'Components'); attr_id := acs_rel_type__create_type ( - ''composition_rel'', - ''Composition Relation'', - ''Composition Relationships'', - ''relationship'', - ''composition_rels'', - ''rel_id'', - ''composition_rel'', - ''group'', - ''composite'', + 'composition_rel', + 'Composition Relation', + 'Composition Relationships', + 'relationship', + 'composition_rels', + 'rel_id', + 'composition_rel', + 'group', + 'composite', 0, null, - ''group'', - ''component'', + 'group', + 'component', 0, null ); @@ -109,51 +115,52 @@ -- -- Membership Relationship -- - attr_id := acs_rel_type__create_role (''member'', ''#acs-kernel.member_role_pretty_name#'', ''#acs-kernel.member_role_pretty_plural#''); + attr_id := acs_rel_type__create_role ('member', '#acs-kernel.member_role_pretty_name#', '#acs-kernel.member_role_pretty_plural#'); attr_id := acs_rel_type__create_type ( - ''membership_rel'', -- rel_type - ''#acs-kernel.Membership_Relation#'', -- pretty_name - ''#acs-kernel.lt_Membership_Relationsh#'', -- pretty_plural - ''relationship'', -- supertype - ''membership_rels'', -- table_name - ''rel_id'', -- id_column - ''membership_rel'', -- package_name - ''group'', -- object_type_one + 'membership_rel', -- rel_type + '#acs-kernel.Membership_Relation#', -- pretty_name + '#acs-kernel.lt_Membership_Relationsh#', -- pretty_plural + 'relationship', -- supertype + 'membership_rels', -- table_name + 'rel_id', -- id_column + 'membership_rel', -- package_name + 'group', -- object_type_one null, -- role_one 0, -- min_n_rels_one null, -- max_n_rels_one - ''person'', -- object_type_two - ''member'', -- role_two + 'person', -- object_type_two + 'member', -- role_two 0, -- min_n_rels_two null -- max_n_rels_two ); -- -- Administrator Relationship -- - attr_id := acs_rel_type__create_role (''admin'', ''#acs-kernel.Administrator#'', ''#acs-kernel.Administrators#''); + attr_id := acs_rel_type__create_role ('admin', '#acs-kernel.Administrator#', '#acs-kernel.Administrators#'); attr_id := acs_rel_type__create_type ( - ''admin_rel'', -- rel_type - ''#acs-kernel.lt_Administrator_Relatio#'', -- pretty_name - ''#acs-kernel.lt_Administrator_Relatio_1#'', -- pretty_plural - ''membership_rel'', -- supertype - ''admin_rels'', -- table_name - ''rel_id'', -- id_column - ''admin_rel'', -- package_name - ''group'', -- object_type_one + 'admin_rel', -- rel_type + '#acs-kernel.lt_Administrator_Relatio#', -- pretty_name + '#acs-kernel.lt_Administrator_Relatio_1#', -- pretty_plural + 'membership_rel', -- supertype + 'admin_rels', -- table_name + 'rel_id', -- id_column + 'admin_rel', -- package_name + 'group', -- object_type_one null, -- role_one 0, -- min_n_rels_one null, -- max_n_rels_one - ''person'', -- object_type_two - ''admin'', -- role_two + 'person', -- object_type_two + 'admin', -- role_two 0, -- min_n_rels_two null -- max_n_rels_two ); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select inline_0 (); @@ -361,25 +368,33 @@ -- FUNCTIONS -- --------------- -- drop function group_contains_p (integer, integer, integer); -create function group_contains_p (integer, integer, integer) -returns boolean as ' -declare - group_contains_p__group_id alias for $1; - group_contains_p__component_id alias for $2; - group_contains_p__rel_id alias for $3; + + +-- added +select define_function_args('group_contains_p','group_id,component_id,rel_id'); + +-- +-- procedure group_contains_p/3 +-- +CREATE OR REPLACE FUNCTION group_contains_p( + group_contains_p__group_id integer, + group_contains_p__component_id integer, + group_contains_p__rel_id integer +) RETURNS boolean AS $$ +DECLARE map record; -begin +BEGIN if group_contains_p__group_id = group_contains_p__component_id then - return ''t''; + return 't'; else if group_contains_p__rel_id is null then for map in select * from group_component_map where component_id = group_contains_p__component_id and group_id = container_id LOOP - if group_contains_p(group_contains_p__group_id, map.group_id, null) = ''t'' then - return ''t''; + if group_contains_p(group_contains_p__group_id, map.group_id, null) = 't' then + return 't'; end if; end loop; else @@ -389,14 +404,15 @@ and rel_id = group_contains_p__rel_id and group_id = container_id LOOP - if group_contains_p(group_contains_p__group_id, map.group_id, null) = ''t'' then - return ''t''; + if group_contains_p(group_contains_p__group_id, map.group_id, null) = 't' then + return 't'; end if; end loop; end if; - return ''f''; + return 'f'; end if; -end;' language 'plpgsql' stable; +END; +$$ LANGUAGE plpgsql stable; @@ -412,29 +428,45 @@ -- sourced. That file will replace these triggers with triggers -- that actually do useful work -create function membership_rels_in_tr () returns trigger as ' -declare -begin - raise EXCEPTION ''-20000: Insert to membership rels not yet supported''; + +-- +-- procedure membership_rels_in_tr/0 +-- +CREATE OR REPLACE FUNCTION membership_rels_in_tr( + +) RETURNS trigger AS $$ +DECLARE +BEGIN + raise EXCEPTION '-20000: Insert to membership rels not yet supported'; + return new; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; create trigger membership_rels_in_tr after insert on membership_rels for each row execute procedure membership_rels_in_tr (); -- show errors -create function composition_rels_in_tr () returns trigger as ' -declare -begin - raise EXCEPTION ''-20000: Insert to composition rels not yet supported''; + +-- +-- procedure composition_rels_in_tr/0 +-- +CREATE OR REPLACE FUNCTION composition_rels_in_tr( + +) RETURNS trigger AS $$ +DECLARE +BEGIN + raise EXCEPTION '-20000: Insert to composition rels not yet supported'; + return new; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; create trigger composition_rels_in_tr after insert on composition_rels for each row execute procedure composition_rels_in_tr(); Index: openacs-4/packages/acs-kernel/sql/postgresql/journal-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/postgresql/journal-create.sql,v diff -u -r1.10 -r1.11 --- openacs-4/packages/acs-kernel/sql/postgresql/journal-create.sql 25 Sep 2006 17:59:16 -0000 1.10 +++ openacs-4/packages/acs-kernel/sql/postgresql/journal-create.sql 7 Jul 2011 10:46:02 -0000 1.11 @@ -12,25 +12,25 @@ -- http://www.fsf.org/copyleft/gpl.html -create function inline_0 () -returns integer as ' -begin +CREATE OR REPLACE FUNCTION inline_0 () RETURNS integer AS $$ +BEGIN PERFORM acs_object_type__create_type ( - ''journal_entry'', - ''Journal Entry'', - ''Journal Entries'', - ''acs_object'', - ''journal_entries'', - ''journal_id'', - ''journal_entry'', - ''f'', + 'journal_entry', + 'Journal Entry', + 'Journal Entries', + 'acs_object', + 'journal_entries', + 'journal_id', + 'journal_entry', + 'f', null, null ); -- XXX fill in all the attributes in later. return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select inline_0 (); @@ -88,27 +88,36 @@ -- create or replace package body journal_entry -- function new -create function journal_entry__new (integer,integer,varchar,varchar,timestamptz,integer,varchar,varchar) -returns integer as ' -declare - new__journal_id alias for $1; -- default null - new__object_id alias for $2; - new__action alias for $3; - new__action_pretty alias for $4; -- default null - new__creation_date alias for $5; -- default now() - new__creation_user alias for $6; -- default null - new__creation_ip alias for $7; -- default null - new__msg alias for $8; -- default null + + +-- added +select define_function_args('journal_entry__new','journal_id;null,object_id,action,action_pretty;null,creation_date;now(),creation_user;null,creation_ip;null,msg;null'); + +-- +-- procedure journal_entry__new/8 +-- +CREATE OR REPLACE FUNCTION journal_entry__new( + new__journal_id integer, -- default null + new__object_id integer, + new__action varchar, + new__action_pretty varchar, -- default null + new__creation_date timestamptz, -- default now() + new__creation_user integer, -- default null + new__creation_ip varchar, -- default null + new__msg varchar -- default null + +) RETURNS integer AS $$ +DECLARE v_journal_id journal_entries.journal_id%TYPE; -begin +BEGIN v_journal_id := acs_object__new ( new__journal_id, - ''journal_entry'', + 'journal_entry', new__creation_date, new__creation_user, new__creation_ip, new__object_id, - ''t'', + 't', new__action, null ); @@ -122,29 +131,47 @@ return v_journal_id; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure delete -create function journal_entry__delete (integer) -returns integer as ' -declare - delete__journal_id alias for $1; -begin + + +-- added +select define_function_args('journal_entry__delete','journal_id'); + +-- +-- procedure journal_entry__delete/1 +-- +CREATE OR REPLACE FUNCTION journal_entry__delete( + delete__journal_id integer +) RETURNS integer AS $$ +DECLARE +BEGIN delete from journal_entries where journal_id = delete__journal_id; PERFORM acs_object__delete(delete__journal_id); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure delete_for_object -create function journal_entry__delete_for_object (integer) -returns integer as ' -declare - delete_for_object__object_id alias for $1; + + +-- added +select define_function_args('journal_entry__delete_for_object','object_id'); + +-- +-- procedure journal_entry__delete_for_object/1 +-- +CREATE OR REPLACE FUNCTION journal_entry__delete_for_object( + delete_for_object__object_id integer +) RETURNS integer AS $$ +DECLARE journal_rec record; -begin +BEGIN for journal_rec in select journal_id from journal_entries where object_id = delete_for_object__object_id @@ -153,7 +180,8 @@ end loop; return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; Index: openacs-4/packages/acs-kernel/sql/postgresql/journal-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/postgresql/journal-drop.sql,v diff -u -r1.2 -r1.3 --- openacs-4/packages/acs-kernel/sql/postgresql/journal-drop.sql 18 Jun 2004 18:21:57 -0000 1.2 +++ openacs-4/packages/acs-kernel/sql/postgresql/journal-drop.sql 7 Jul 2011 10:46:02 -0000 1.3 @@ -9,13 +9,14 @@ -- \t -create function inline_0 () returns integer as ' -begin +CREATE OR REPLACE FUNCTION inline_0 () RETURNS integer AS $$ +BEGIN PERFORM acs_object_type__drop_type( - ''journal_entry'', ''f'' + 'journal_entry', 'f' ); return null; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select inline_0 (); drop function inline_0 (); Index: openacs-4/packages/acs-kernel/sql/postgresql/lob.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/postgresql/lob.sql,v diff -u -r1.6 -r1.7 --- openacs-4/packages/acs-kernel/sql/postgresql/lob.sql 10 Mar 2010 00:44:03 -0000 1.6 +++ openacs-4/packages/acs-kernel/sql/postgresql/lob.sql 7 Jul 2011 10:46:02 -0000 1.7 @@ -24,14 +24,15 @@ refcount integer not null default 0 ); -create or replace function on_lobs_delete() returns trigger as ' -begin +CREATE OR REPLACE FUNCTION lobs_delete_tr() RETURNS trigger AS $$ +BEGIN delete from lob_data where lob_id = old.lob_id; return old; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create trigger lobs_delete_trig before delete on lobs -for each row execute procedure on_lobs_delete(); +create trigger lobs_delete_tr before delete on lobs +for each row execute procedure lobs_delete_tr(); create table lob_data ( lob_id integer not null @@ -51,62 +52,83 @@ -- and PG 7.0. The ACS doesn't share LOBs between tables -- or rows within a table anyway, I don't think/hope. -create or replace function on_lob_ref() returns trigger as ' -begin - if TG_OP = ''UPDATE'' then +CREATE OR REPLACE FUNCTION on_lob_ref() RETURNS trigger AS $$ +BEGIN + if TG_OP = 'UPDATE' then if new.lob = old.lob then return new; end if; end if; - if TG_OP = ''INSERT'' or TG_OP = ''UPDATE'' then + if TG_OP = 'INSERT' or TG_OP = 'UPDATE' then if new.lob is not null then insert into lobs select new.lob, 0 where 0 = (select count(*) from lobs where lob_id = new.lob); update lobs set refcount = refcount + 1 where lob_id = new.lob; end if; end if; - if TG_OP <> ''INSERT'' then + if TG_OP <> 'INSERT' then if old.lob is not null then update lobs set refcount = refcount - 1 where lob_id = old.lob; delete from lobs where lob_id = old.lob and refcount = 0; end if; end if; - if TG_OP = ''INSERT'' or TG_OP = ''UPDATE'' then return new; + if TG_OP = 'INSERT' or TG_OP = 'UPDATE' then return new; else return old; end if; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create or replace function empty_lob() returns integer as ' -begin - return nextval(''lob_sequence''); -end;' language 'plpgsql'; +CREATE OR REPLACE FUNCTION empty_lob() RETURNS integer AS $$ +BEGIN + return nextval('lob_sequence'); +END; +$$ LANGUAGE plpgsql; -create or replace function lob_get_data(integer) returns text as ' -declare - p_lob_id alias for $1; + + +-- added +select define_function_args('lob_get_data','lob_id'); + +-- +-- procedure lob_get_data/1 +-- +CREATE OR REPLACE FUNCTION lob_get_data( + p_lob_id integer +) RETURNS text AS $$ +DECLARE v_rec record; - v_data text default ''''; -begin + v_data text default ''; +BEGIN for v_rec in select data, segment from lob_data where lob_id = p_lob_id order by segment loop v_data := v_data || v_rec.data; end loop; return v_data; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create or replace function lob_copy(integer, integer) returns integer as ' -declare - from_id alias for $1; - to_id alias for $2; -begin + + +-- added +select define_function_args('lob_copy','from_id,to_id'); + +-- +-- procedure lob_copy/2 +-- +CREATE OR REPLACE FUNCTION lob_copy( + from_id integer, + to_id integer +) RETURNS integer AS $$ +DECLARE +BEGIN if from_id is null then - raise exception ''lob_copy: attempt to copy null from_id to % to_id'',to_id; + raise exception 'lob_copy: attempt to copy null from_id to % to_id',to_id; end if; insert into lobs (lob_id,refcount) values (to_id,0); @@ -118,11 +140,22 @@ return null; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create or replace function lob_length(integer) returns integer as ' -declare - id alias for $1; -begin + + +-- added +select define_function_args('lob_length','id'); + +-- +-- procedure lob_length/1 +-- +CREATE OR REPLACE FUNCTION lob_length( + id integer +) RETURNS integer AS $$ +DECLARE +BEGIN return sum(byte_len) from lob_data where lob_id = id; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; Index: openacs-4/packages/acs-kernel/sql/postgresql/postgresql.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/postgresql/postgresql.sql,v diff -u -r1.42 -r1.43 --- openacs-4/packages/acs-kernel/sql/postgresql/postgresql.sql 21 Jul 2009 23:39:33 -0000 1.42 +++ openacs-4/packages/acs-kernel/sql/postgresql/postgresql.sql 7 Jul 2011 10:46:02 -0000 1.43 @@ -5,23 +5,29 @@ create view anon_func_seq as select nextval('t_anon_func_seq') as nextval; -create or replace function instr(varchar,char,integer,integer) returns integer as ' -declare - str alias for $1; - pat alias for $2; - dir alias for $3; - cnt alias for $4; + + +-- +-- procedure instr/4 +-- +CREATE OR REPLACE FUNCTION instr( + str varchar, + pat char, + dir integer, + cnt integer +) RETURNS integer AS $$ +DECLARE v_len integer; v_i integer; v_c char; v_cnt integer; v_inc integer; -begin +BEGIN v_len := length(str); v_cnt := 0; if dir < 0 then - v_inc := \-1; + v_inc := -1; v_i := v_len; else v_inc := 1; @@ -41,42 +47,62 @@ return 0; -end;' language 'plpgsql' immutable; +END; +$$ LANGUAGE plpgsql immutable; -create or replace function instr(varchar,char,integer) returns integer as ' -declare - str alias for $1; - pat alias for $2; - dir alias for $3; -begin + + +-- +-- procedure instr/3 +-- +CREATE OR REPLACE FUNCTION instr( + str varchar, + pat char, + dir integer +) RETURNS integer AS $$ +DECLARE +BEGIN return instr(str,pat,dir,1); -end;' language 'plpgsql' immutable; +END; +$$ LANGUAGE plpgsql immutable; -create or replace function instr(varchar,char) returns integer as ' -declare - str alias for $1; - pat alias for $2; -begin + + +-- +-- procedure instr/2 +-- +CREATE OR REPLACE FUNCTION instr( + str varchar, + pat char +) RETURNS integer AS $$ +DECLARE +BEGIN return instr(str,pat,1,1); -end;' language 'plpgsql' immutable; +END; +$$ LANGUAGE plpgsql immutable; -- Splits string on requested character. Returns requested element -- (1-based) -create or replace function split(varchar,char,integer) -returns varchar as ' -declare - p_string alias for $1; - p_split_char alias for $2; - p_element alias for $3; + +-- +-- procedure split/3 +-- +CREATE OR REPLACE FUNCTION split( + p_string varchar, + p_split_char char, + p_element integer +) RETURNS varchar AS $$ +DECLARE + v_left_split integer; v_right_split integer; v_len integer; -begin +BEGIN v_len = length(p_string); if v_len = 0 or p_string is null or p_element <= 0 then return NULL; @@ -94,175 +120,211 @@ return null; end if; return substr(p_string, v_left_split+1, (v_right_split - v_left_split - 1)); -end;' language 'plpgsql' immutable; +END; +$$ LANGUAGE plpgsql immutable; -create or replace function get_func_drop_command (varchar) returns varchar as ' -declare - fname alias for $1; + + +-- +-- procedure get_func_drop_command/1 +-- +CREATE OR REPLACE FUNCTION get_func_drop_command( + fname varchar +) RETURNS varchar AS $$ +DECLARE nargs integer default 0; v_pos integer; v_funcdef text; v_args varchar; v_one_arg varchar; v_one_type varchar; v_nargs integer; -begin - v_funcdef := ''drop function '' || fname || ''(''; +BEGIN + v_funcdef := 'drop function ' || fname || '('; select proargtypes, pronargs into v_args, v_nargs from pg_proc where proname = fname::name; - v_pos := position('' '' in v_args); + v_pos := position(' ' in v_args); while nargs < v_nargs loop nargs := nargs + 1; if nargs = v_nargs then v_one_arg := v_args; - v_args := ''''; + v_args := ''; else - v_one_arg := substr(v_args, 1, v_pos \- 1); + v_one_arg := substr(v_args, 1, v_pos - 1); v_args := substr(v_args, v_pos + 1); - v_pos := position('' '' in v_args); + v_pos := position(' ' in v_args); end if; select case when nargs = 1 then typname - else '','' || typname + else ',' || typname end into v_one_type from pg_type where oid = v_one_arg::integer; v_funcdef := v_funcdef || v_one_type; end loop; - v_funcdef := v_funcdef || '') CASCADE''; + v_funcdef := v_funcdef || ') CASCADE'; return v_funcdef; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create or replace function drop_package (varchar) returns varchar as ' -declare - package_name alias for $1; + + +-- +-- procedure drop_package/1 +-- +CREATE OR REPLACE FUNCTION drop_package( + package_name varchar +) RETURNS varchar AS $$ +DECLARE v_rec record; v_drop_cmd varchar; v_pkg_name varchar; -begin - raise NOTICE ''DROP PACKAGE: %'', package_name; - v_pkg_name := package_name || ''\\\\_\\\\_'' || ''%''; +BEGIN + raise NOTICE 'DROP PACKAGE: %', package_name; + v_pkg_name := package_name || '__' || '%'; for v_rec in select proname from pg_proc where proname like v_pkg_name order by proname LOOP - raise NOTICE ''DROPPING FUNCTION: %'', v_rec.proname; + raise NOTICE 'DROPPING FUNCTION: %', v_rec.proname; v_drop_cmd := get_func_drop_command (v_rec.proname::varchar); EXECUTE v_drop_cmd; end loop; if NOT FOUND then - raise NOTICE ''PACKAGE: % NOT FOUND'', package_name; + raise NOTICE 'PACKAGE: % NOT FOUND', package_name; else - raise NOTICE ''PACKAGE: %: DROPPED'', package_name; + raise NOTICE 'PACKAGE: %: DROPPED', package_name; end if; return null; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create or replace function number_src(text) returns text as ' -declare - v_src alias for $1; + + +-- +-- procedure number_src/1 +-- +CREATE OR REPLACE FUNCTION number_src( + v_src text +) RETURNS text AS $$ +DECLARE v_pos integer; - v_ret text default ''''; + v_ret text default ''; v_tmp text; v_cnt integer default -1; -begin +BEGIN if v_src is null then return null; end if; v_tmp := v_src; LOOP - v_pos := position(''\n'' in v_tmp); + v_pos := position(E'\n' in v_tmp); v_cnt := v_cnt + 1; exit when v_pos = 0; if v_cnt != 0 then - v_ret := v_ret || to_char(v_cnt,''9999'') || '':'' || substr(v_tmp,1,v_pos); + v_ret := v_ret || to_char(v_cnt,'9999') || ':' || substr(v_tmp,1,v_pos); end if; v_tmp := substr(v_tmp,v_pos + 1); end LOOP; - return v_ret || to_char(v_cnt,''9999'') || '':'' || v_tmp; + return v_ret || to_char(v_cnt,'9999') || ':' || v_tmp; -end;' language 'plpgsql' immutable strict; +END; +$$ LANGUAGE plpgsql immutable strict; -create or replace function get_func_definition (varchar,oidvector) returns text as ' -declare - fname alias for $1; - args alias for $2; + + +-- +-- procedure get_func_definition/2 +-- +CREATE OR REPLACE FUNCTION get_func_definition( + fname varchar, + args oidvector +) RETURNS text AS $$ +DECLARE nargs integer default 0; v_pos integer; - v_funcdef text default ''''; + v_funcdef text default ''; v_args varchar; v_one_arg varchar; v_one_type varchar; v_nargs integer; v_src text; v_rettype varchar; -begin +BEGIN select proargtypes, pronargs, number_src(prosrc), (select typname from pg_type where oid = p.prorettype::integer) into v_args, v_nargs, v_src, v_rettype from pg_proc p where proname = fname::name and proargtypes = args; - v_funcdef := v_funcdef || '' -create or replace function '' || fname || ''(''; + v_funcdef := v_funcdef || ' +create or replace function ' || fname || '('; - v_pos := position('' '' in v_args); + v_pos := position(' ' in v_args); while nargs < v_nargs loop nargs := nargs + 1; if nargs = v_nargs then v_one_arg := v_args; - v_args := ''''; + v_args := ''; else - v_one_arg := substr(v_args, 1, v_pos \- 1); + v_one_arg := substr(v_args, 1, v_pos - 1); v_args := substr(v_args, v_pos + 1); - v_pos := position('' '' in v_args); + v_pos := position(' ' in v_args); end if; select case when nargs = 1 then typname - else '','' || typname + else ',' || typname end into v_one_type from pg_type where oid = v_one_arg::integer; v_funcdef := v_funcdef || v_one_type; end loop; - v_funcdef := v_funcdef || '') returns '' || v_rettype || '' as \\\'\\n'' || v_src || ''\\\' language \\\'plpgsql\\\';''; + v_funcdef := v_funcdef || ') returns ' || v_rettype || E' as ''\n' || v_src || ''' language ''plpgsql'';'; return v_funcdef; -end;' language 'plpgsql' stable strict; +END; +$$ LANGUAGE plpgsql stable strict; -create or replace function get_func_header(varchar,oidvector) returns text as ' -declare - fname alias for $1; - args alias for $2; + + +-- +-- procedure get_func_header/2 +-- +CREATE OR REPLACE FUNCTION get_func_header( + fname varchar, + args oidvector +) RETURNS text AS $$ +DECLARE v_src text; pos integer; -begin +BEGIN v_src := get_func_definition(fname,args); - pos := position(''begin'' in lower(v_src)); + pos := position('begin' in lower(v_src)); return substr(v_src, 1, pos + 4); -end;' language 'plpgsql' stable strict; +END; +$$ LANGUAGE plpgsql stable strict; create view acs_func_defs as select get_func_definition(proname::varchar,proargtypes) as definition, @@ -276,40 +338,56 @@ ---------------------------------------------------------------------------- -create or replace function inline_0 () returns integer as ' --- Create a bitfromint4(integer) function if it doesn''t exists. + + +-- +-- procedure inline_0/0 +-- +CREATE OR REPLACE FUNCTION inline_0( + +) RETURNS integer AS $$ +-- Create a bitfromint4(integer) function if it doesn't exists. -- This function is no longer present in 7.3 and above -declare +DECLARE v_bitfromint4_count integer; -begin - select into v_bitfromint4_count count(*) from pg_proc where proname = ''bitfromint4''; +BEGIN + select into v_bitfromint4_count count(*) from pg_proc where proname = 'bitfromint4'; if v_bitfromint4_count = 0 then - create or replace function bitfromint4 (integer) returns bit varying as '' + create or replace function bitfromint4 (integer) returns bit varying as ' begin return $1::bit(32); - end;'' language ''plpgsql'' immutable strict; + end;' language 'plpgsql' immutable strict; end if; return 1; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select inline_0(); drop function inline_0(); -create or replace function inline_1 () returns integer as ' --- Create a bitfromint4(integer) function if it doesn''t exists. + + +-- +-- procedure inline_1/0 +-- +CREATE OR REPLACE FUNCTION inline_1( + +) RETURNS integer AS $$ +-- Create a bitfromint4(integer) function if it doesn't exists. -- This function is no longer present in 7.3 and above -declare +DECLARE v_bittoint4_count integer; -begin - select into v_bittoint4_count count(*) from pg_proc where proname = ''bittoint4''; +BEGIN + select into v_bittoint4_count count(*) from pg_proc where proname = 'bittoint4'; if v_bittoint4_count = 0 then - create or replace function bittoint4 (bit varying) returns integer as '' + create or replace function bittoint4 (bit varying) returns integer as ' begin return "int4"($1); - end;'' language ''plpgsql'' immutable strict; + end;' language 'plpgsql' immutable strict; end if; return 1; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select inline_1(); drop function inline_1(); @@ -347,8 +425,14 @@ -- SQL92 standard "bit varying" so I've used the synonym "varbit" -- throughout. -create or replace function int_to_tree_key(integer) returns varbit as ' + +-- +-- procedure int_to_tree_key/1 +-- +CREATE OR REPLACE FUNCTION int_to_tree_key( + p_intkey integer +) RETURNS varbit AS $$ -- Convert an integer into the bit string format used to store -- tree sort keys. Using 4 bytes for the long keys requires -- using -2^31 rather than 2^31 to avoid a twos-complement @@ -358,12 +442,10 @@ -- There was an "out of range" check in here when I was using 15 -- bit long keys but the only check that does anything with the long -- keys is to check for negative numbers. - -declare - p_intkey alias for $1; -begin +DECLARE +BEGIN if p_intkey < 0 then - raise exception ''int_to_tree_key: key must be a positive integer''; + raise exception 'int_to_tree_key: key must be a positive integer'; end if; if p_intkey < 128 then @@ -372,63 +454,73 @@ return substring(bitfromint4(cast (-2^31 + p_intkey as int4)), 1, 32); end if; -end;' language 'plpgsql' immutable strict; +END; +$$ LANGUAGE plpgsql immutable strict; -create or replace function tree_key_to_int(varbit, integer) returns integer as ' + +-- +-- procedure tree_key_to_int/2 +-- +CREATE OR REPLACE FUNCTION tree_key_to_int( + p_tree_key varbit, + p_level integer +) RETURNS integer AS $$ -- Convert the compressed key for the node at the given level to an -- integer. - -declare - p_tree_key alias for $1; - p_level alias for $2; +DECLARE v_level integer default 0; v_parent_pos integer default 1; v_pos integer default 1; -begin +BEGIN -- Find the right key first while v_pos < length(p_tree_key) and v_level < p_level loop v_parent_pos := v_pos; v_level := v_level + 1; - if substring(p_tree_key, v_pos, 1) = ''1'' then + if substring(p_tree_key, v_pos, 1) = '1' then v_pos := v_pos + 32; else v_pos := v_pos + 8; end if; end loop; if v_level < p_level then - raise exception ''tree_key_to_int: key is at a level less than %'', p_level; + raise exception 'tree_key_to_int: key is at a level less than %', p_level; end if; - if substring(p_tree_key, v_parent_pos, 1) = ''1'' then + if substring(p_tree_key, v_parent_pos, 1) = '1' then return bittoint4(substring(p_tree_key, v_parent_pos + 1, 31)); else return bittoint4(substring(p_tree_key, v_parent_pos, 8)); end if; -end;' language 'plpgsql' immutable strict; +END; +$$ LANGUAGE plpgsql immutable strict; -create or replace function tree_ancestor_key(varbit, integer) returns varbit as ' + +-- +-- procedure tree_ancestor_key/2 +-- +CREATE OR REPLACE FUNCTION tree_ancestor_key( + p_tree_key varbit, + p_level integer +) RETURNS varbit AS $$ -- Returns a key for the ancestor at the given level. The root is level -- one. - -declare - p_tree_key alias for $1; - p_level alias for $2; +DECLARE v_level integer default 0; v_pos integer default 1; -begin +BEGIN if tree_level(p_tree_key) < p_level then - raise exception ''tree_ancestor_key: key is at a level less than %'', p_level; + raise exception 'tree_ancestor_key: key is at a level less than %', p_level; end if; while v_level < p_level loop v_level := v_level + 1; - if substring(p_tree_key, v_pos, 1) = ''1'' then + if substring(p_tree_key, v_pos, 1) = '1' then v_pos := v_pos + 32; else v_pos := v_pos + 8; @@ -437,60 +529,77 @@ return substring(p_tree_key, 1, v_pos - 1); -end;' language 'plpgsql' immutable strict; +END; +$$ LANGUAGE plpgsql immutable strict; -create or replace function tree_root_key(varbit) returns varbit as ' + +-- +-- procedure tree_root_key/1 +-- +CREATE OR REPLACE FUNCTION tree_root_key( + p_tree_key varbit +) RETURNS varbit AS $$ -- Return the tree_sortkey for the root node of the node with the --- given tree_sortkey. +-- given tree_sortkey. +DECLARE +BEGIN -declare - p_tree_key alias for $1; -begin - - if substring(p_tree_key, 1, 1) = ''1'' then + if substring(p_tree_key, 1, 1) = '1' then return substring(p_tree_key, 1, 32); else return substring(p_tree_key, 1, 8); end if; -end;' language 'plpgsql' immutable strict; +END; +$$ LANGUAGE plpgsql immutable strict; -create or replace function tree_leaf_key_to_int(varbit) returns integer as ' + +-- +-- procedure tree_leaf_key_to_int/1 +-- +CREATE OR REPLACE FUNCTION tree_leaf_key_to_int( + p_tree_key varbit +) RETURNS integer AS $$ -- Convert the bitstring for the last, or leaf, node represented by this key -- to an integer. - -declare - p_tree_key alias for $1; +DECLARE v_leaf_pos integer default 1; v_pos integer default 1; -begin +BEGIN -- Find the leaf key first while v_pos < length(p_tree_key) loop v_leaf_pos := v_pos; - if substring(p_tree_key, v_pos, 1) = ''1'' then + if substring(p_tree_key, v_pos, 1) = '1' then v_pos := v_pos + 32; else v_pos := v_pos + 8; end if; end loop; - if substring(p_tree_key, v_leaf_pos, 1) = ''1'' then + if substring(p_tree_key, v_leaf_pos, 1) = '1' then return bittoint4(substring(p_tree_key, v_leaf_pos + 1, 31)); else return bittoint4(substring(p_tree_key, v_leaf_pos, 8)); end if; -end;' language 'plpgsql' immutable strict; +END; +$$ LANGUAGE plpgsql immutable strict; -create or replace function tree_next_key(varbit, integer) returns varbit as ' -declare - p_parent_key alias for $1; - p_child_value alias for $2; + + +-- +-- procedure tree_next_key/2 +-- +CREATE OR REPLACE FUNCTION tree_next_key( + p_parent_key varbit, + p_child_value integer +) RETURNS varbit AS $$ +DECLARE v_child_value integer; -begin +BEGIN -- Create a new child of the given key with a leaf key number one greater than -- the child value parameter. If the child value parameter is null, make the -- child the first child of the parent. @@ -507,65 +616,86 @@ return p_parent_key || int_to_tree_key(v_child_value); end if; -end;' language 'plpgsql' immutable; +END; +$$ LANGUAGE plpgsql immutable; -create or replace function tree_increment_key(varbit) -returns varbit as ' -declare - p_child_sort_key alias for $1; + + +-- +-- procedure tree_increment_key/1 +-- +CREATE OR REPLACE FUNCTION tree_increment_key( + p_child_sort_key varbit +) RETURNS varbit AS $$ +DECLARE v_child_sort_key integer; -begin +BEGIN if p_child_sort_key is null then v_child_sort_key := 0; else v_child_sort_key := tree_leaf_key_to_int(p_child_sort_key) + 1; end if; return int_to_tree_key(v_child_sort_key); -end;' language 'plpgsql' immutable; +END; +$$ LANGUAGE plpgsql immutable; -create or replace function tree_left(varbit) returns varbit as ' + +-- +-- procedure tree_left/1 +-- +CREATE OR REPLACE FUNCTION tree_left( + key varbit +) RETURNS varbit AS $$ -- Create a key less than or equal to that of any child of the -- current key. - -declare - key alias for $1; -begin +DECLARE +BEGIN if key is null then - return ''X00''::varbit; + return 'X00'::varbit; else - return key || ''X00''::varbit; + return key || 'X00'::varbit; end if; -end;' language 'plpgsql' immutable; +END; +$$ LANGUAGE plpgsql immutable; -create or replace function tree_right(varbit) returns varbit as ' + +-- +-- procedure tree_right/1 +-- +CREATE OR REPLACE FUNCTION tree_right( + key varbit +) RETURNS varbit AS $$ -- Create a key greater or equal to that of any child of the current key. -- Used in BETWEEN expressions to select the subtree rooted at the given --- key. - -declare - key alias for $1; -begin +-- key. +DECLARE +BEGIN if key is null then - return ''XFFFFFFFF''::varbit; + return 'XFFFFFFFF'::varbit; else - return key || ''XFFFFFFFF''::varbit; + return key || 'XFFFFFFFF'::varbit; end if; -end;' language 'plpgsql' immutable; +END; +$$ LANGUAGE plpgsql immutable; -create or replace function tree_level(varbit) returns integer as ' + +-- +-- procedure tree_level/1 +-- +CREATE OR REPLACE FUNCTION tree_level( + p_tree_key varbit +) RETURNS integer AS $$ -- Return the tree level of the given key. The root level is defined -- to be at level one. - -declare - p_tree_key alias for $1; +DECLARE v_pos integer; v_level integer; -begin +BEGIN if p_tree_key is null then return 0; @@ -576,23 +706,31 @@ while v_pos <= length(p_tree_key) loop v_level := v_level + 1; - if substring(p_tree_key, v_pos, 1) = ''1'' then + if substring(p_tree_key, v_pos, 1) = '1' then v_pos := v_pos + 32; else v_pos := v_pos + 8; end if; end loop; return v_level; -end;' language 'plpgsql' immutable; +END; +$$ LANGUAGE plpgsql immutable; -create or replace function tree_ancestor_p(varbit, varbit) returns boolean as ' -declare - p_potential_ancestor alias for $1; - p_potential_child alias for $2; -begin + + +-- +-- procedure tree_ancestor_p/2 +-- +CREATE OR REPLACE FUNCTION tree_ancestor_p( + p_potential_ancestor varbit, + p_potential_child varbit +) RETURNS boolean AS $$ +DECLARE +BEGIN return position(p_potential_ancestor in p_potential_child) = 1; -end;' language 'plpgsql' immutable; +END; +$$ LANGUAGE plpgsql immutable; -- PG does not allow recursive SQL functions during CREATE, but you can fool it easily -- with CREATE OR REPLACE, a feature added in 7.2. @@ -608,9 +746,6 @@ select $1 ' language 'sql'; --- The bootstrap installer has made certain that we are running a version >= 7.2 so it is safe --- at this point to assume create or replace is supported. - create or replace function tree_ancestor_keys(varbit, integer) returns setof varbit as ' select tree_ancestor_key($1, $2) union @@ -722,24 +857,28 @@ -- Add entries to acs_function_args for one function -- Usage: select define_function_args('function_name','arg1,arg2;default,arg3,arg4;default') -create or replace function define_function_args(varchar,varchar) -returns integer as ' -declare - p_function alias for $1; - p_arg_list alias for $2; +-- +-- procedure define_function_args/2 +-- +CREATE OR REPLACE FUNCTION define_function_args( + p_function varchar, + p_arg_list varchar +) RETURNS integer AS $$ +DECLARE + v_arg_seq integer default 1; v_arg_name varchar; v_arg_default varchar; v_elem varchar; v_pos integer; -begin +BEGIN delete from acs_function_args where function = upper(trim(p_function)); - v_elem = split(p_arg_list, '','', v_arg_seq); + v_elem = split(p_arg_list, ',', v_arg_seq); while v_elem is not null loop - v_pos = instr(v_elem, '';'', 1, 1); + v_pos = instr(v_elem, ';', 1, 1); if v_pos > 0 then v_arg_name := substr(v_elem, 1, v_pos-1); v_arg_default := substr(v_elem, v_pos+1, length(v_elem) - v_pos); @@ -752,52 +891,83 @@ values (upper(trim(p_function)), v_arg_seq, upper(trim(v_arg_name)), v_arg_default); v_arg_seq := v_arg_seq + 1; - v_elem = split(p_arg_list, '','', v_arg_seq); + v_elem = split(p_arg_list, ',', v_arg_seq); end loop; return 1; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- Returns an english-language description of the trigger type. Used by the -- schema browser -create or replace function trigger_type (integer) returns varchar as ' -declare - tgtype alias for $1; + + +-- +-- procedure trigger_type/1 +-- +CREATE OR REPLACE FUNCTION trigger_type( + tgtype integer +) RETURNS varchar AS $$ +DECLARE description varchar; sep varchar; -begin +BEGIN if (tgtype & 2) > 0 then - description := ''BEFORE ''; + description := 'BEFORE '; else - description := ''AFTER ''; + description := 'AFTER '; end if; - sep := ''''; + sep := ''; if (tgtype & 4) > 0 then - description := description || ''INSERT ''; - sep := ''OR ''; + description := description || 'INSERT '; + sep := 'OR '; end if; if (tgtype & 8) > 0 then - description := description || sep || ''DELETE ''; - sep := ''OR ''; + description := description || sep || 'DELETE '; + sep := 'OR '; end if; if (tgtype & 16) > 0 then - description := description || sep || ''UPDATE ''; - sep := ''OR ''; + description := description || sep || 'UPDATE '; + sep := 'OR '; end if; if (tgtype & 1) > 0 then - description := description || ''FOR EACH ROW''; + description := description || 'FOR EACH ROW'; else - description := description || ''STATEMENT''; + description := description || 'STATEMENT'; end if; return description; -end;' language 'plpgsql' with (iscachable); +END; +$$ LANGUAGE plpgsql with (iscachable); + +-- added +select define_function_args('instr','str,pat,dir,cnt'); +select define_function_args('split','string,split_char,element'); +select define_function_args('get_func_drop_command','fname'); +select define_function_args('drop_package','package_name'); +select define_function_args('number_src','v_src'); +select define_function_args('get_func_definition','fname,args'); +select define_function_args('get_func_header','fname,args'); +select define_function_args('int_to_tree_key','intkey'); +select define_function_args('tree_key_to_int','tree_key,level'); +select define_function_args('tree_ancestor_key','tree_key,level'); +select define_function_args('tree_root_key','tree_key'); +select define_function_args('tree_leaf_key_to_int','tree_key'); +select define_function_args('tree_next_key','parent_key,child_value'); +select define_function_args('tree_increment_key','child_sort_key'); +select define_function_args('tree_left','key'); +select define_function_args('tree_right','key'); +select define_function_args('tree_level','tree_key'); +select define_function_args('tree_ancestor_p','potential_ancestor,potential_child'); +select define_function_args('define_function_args','function,arg_list'); +select define_function_args('trigger_type','tgtype'); + Index: openacs-4/packages/acs-kernel/sql/postgresql/rel-constraints-body-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/postgresql/rel-constraints-body-create.sql,v diff -u -r1.11 -r1.12 --- openacs-4/packages/acs-kernel/sql/postgresql/rel-constraints-body-create.sql 12 Mar 2004 18:48:50 -0000 1.11 +++ openacs-4/packages/acs-kernel/sql/postgresql/rel-constraints-body-create.sql 7 Jul 2011 10:46:02 -0000 1.12 @@ -15,16 +15,23 @@ -- create or replace package body rel_constraint -create or replace function rel_constraint__new(varchar,integer,varchar,integer) -returns integer as ' -declare - nam alias for $1; - sid1 alias for $2; - side alias for $3; - sid2 alias for $4; -begin + + +-- added + +-- +-- procedure rel_constraint__new/4 +-- +CREATE OR REPLACE FUNCTION rel_constraint__new( + nam varchar, + sid1 integer, + side varchar, + sid2 integer +) RETURNS integer AS $$ +DECLARE +BEGIN return rel_constraint__new(null, - ''rel_constraint'', + 'rel_constraint', nam, sid1, side, @@ -33,31 +40,41 @@ null, null ); -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function new -create or replace function rel_constraint__new (integer,varchar,varchar,integer,char,integer,integer,integer,varchar) -returns integer as ' -declare - new__constraint_id alias for $1; -- default null - new__constraint_type alias for $2; -- default ''rel_constraint'' - new__constraint_name alias for $3; - new__rel_segment alias for $4; - new__rel_side alias for $5; -- default ''two'' - new__required_rel_segment alias for $6; - new__context_id alias for $7; -- default null - new__creation_user alias for $8; -- default null - new__creation_ip alias for $9; -- default null + + +-- added +select define_function_args('rel_constraint__new','constraint_id;null,constraint_type;rel_constraint,constraint_name,rel_segment,rel_side;two,required_rel_segment,context_id;null,creation_user;null,creation_ip;null'); + +-- +-- procedure rel_constraint__new/9 +-- +CREATE OR REPLACE FUNCTION rel_constraint__new( + new__constraint_id integer, -- default null + new__constraint_type varchar, -- default 'rel_constraint' + new__constraint_name varchar, + new__rel_segment integer, + new__rel_side char, -- default 'two' + new__required_rel_segment integer, + new__context_id integer, -- default null + new__creation_user integer, -- default null + new__creation_ip varchar -- default null + +) RETURNS integer AS $$ +DECLARE v_constraint_id rel_constraints.constraint_id%TYPE; -begin +BEGIN v_constraint_id := acs_object__new ( new__constraint_id, new__constraint_type, now(), new__creation_user, new__creation_ip, new__context_id, - ''t'', + 't', new__constraint_name, null ); @@ -71,48 +88,75 @@ return v_constraint_id; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure delete -create or replace function rel_constraint__delete (integer) -returns integer as ' -declare - constraint_id alias for $1; -begin + + +-- added +select define_function_args('rel_constraint__delete','constraint_id'); + +-- +-- procedure rel_constraint__delete/1 +-- +CREATE OR REPLACE FUNCTION rel_constraint__delete( + constraint_id integer +) RETURNS integer AS $$ +DECLARE +BEGIN PERFORM acs_object__delete(constraint_id); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function get_constraint_id -create or replace function rel_constraint__get_constraint_id (integer,char,integer) -returns integer as ' -declare - get_constraint_id__rel_segment alias for $1; - get_constraint_id__rel_side alias for $2; - get_constraint_id__required_rel_segment alias for $3; + + +-- added +select define_function_args('rel_constraint__get_constraint_id','rel_segment,rel_side,required_rel_segment'); + +-- +-- procedure rel_constraint__get_constraint_id/3 +-- +CREATE OR REPLACE FUNCTION rel_constraint__get_constraint_id( + get_constraint_id__rel_segment integer, + get_constraint_id__rel_side char, + get_constraint_id__required_rel_segment integer +) RETURNS integer AS $$ +DECLARE v_constraint_id rel_constraints.constraint_id%TYPE; -begin +BEGIN return constraint_id from rel_constraints where rel_segment = get_constraint_id__rel_segment and rel_side = get_constraint_id__rel_side and required_rel_segment = get_constraint_id__required_rel_segment; -end;' language 'plpgsql' stable strict; +END; +$$ LANGUAGE plpgsql stable strict; -- function violation -create or replace function rel_constraint__violation (integer) -returns varchar as ' -declare - violation__rel_id alias for $1; + + +-- added +select define_function_args('rel_constraint__violation','rel_id'); + +-- +-- procedure rel_constraint__violation/1 +-- +CREATE OR REPLACE FUNCTION rel_constraint__violation( + violation__rel_id integer +) RETURNS varchar AS $$ +DECLARE v_error text; constraint_violated record; -begin +BEGIN v_error := null; @@ -123,11 +167,11 @@ LIMIT 1 LOOP - v_error := coalesce(v_error,'''') || - ''Relational Constraint Violation: '' || + v_error := coalesce(v_error,'') || + 'Relational Constraint Violation: ' || constraint_violated.constraint_name || - '' (constraint_id='' || - constraint_violated.constraint_id || ''). ''; + ' (constraint_id=' || + constraint_violated.constraint_id || '). '; return v_error; end loop; @@ -139,29 +183,38 @@ LIMIT 1 LOOP - v_error := coalesce(v_error,'''') || - ''Relational Constraint Violation: '' || + v_error := coalesce(v_error,'') || + 'Relational Constraint Violation: ' || constraint_violated.constraint_name || - '' (constraint_id='' || - constraint_violated.constraint_id || ''). ''; + ' (constraint_id=' || + constraint_violated.constraint_id || '). '; return v_error; end loop; return v_error; -end;' language 'plpgsql' stable strict; +END; +$$ LANGUAGE plpgsql stable strict; -- function violation_if_removed -create or replace function rel_constraint__violation_if_removed (integer) -returns varchar as ' -declare - violation_if_removed__rel_id alias for $1; + + +-- added +select define_function_args('rel_constraint__violation_if_removed','rel_id'); + +-- +-- procedure rel_constraint__violation_if_removed/1 +-- +CREATE OR REPLACE FUNCTION rel_constraint__violation_if_removed( + violation_if_removed__rel_id integer +) RETURNS varchar AS $$ +DECLARE v_count integer; v_error text; constraint_violated record; -begin +BEGIN v_error := null; select count(*) into v_count @@ -178,10 +231,10 @@ where r.rel_id = violation_if_removed__rel_id LOOP - v_error := v_error || ''Relational Constraint Violation: '' || + v_error := v_error || 'Relational Constraint Violation: ' || constraint_violated.constraint_name || - '' (constraint_id='' || - constraint_violated.constraint_id || ''). ''; + ' (constraint_id=' || + constraint_violated.constraint_id || '). '; end loop; @@ -190,7 +243,8 @@ return v_error; -end;' language 'plpgsql' stable strict; +END; +$$ LANGUAGE plpgsql stable strict; Index: openacs-4/packages/acs-kernel/sql/postgresql/rel-constraints-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/postgresql/rel-constraints-create.sql,v diff -u -r1.17 -r1.18 --- openacs-4/packages/acs-kernel/sql/postgresql/rel-constraints-create.sql 10 Mar 2010 00:44:03 -0000 1.17 +++ openacs-4/packages/acs-kernel/sql/postgresql/rel-constraints-create.sql 7 Jul 2011 10:46:02 -0000 1.18 @@ -17,24 +17,24 @@ -- change in the future, particularly the functions marked "EXPERIMENTAL". -- -create function inline_0 () -returns integer as ' -begin +CREATE OR REPLACE FUNCTION inline_0 () RETURNS integer AS $$ +BEGIN PERFORM acs_object_type__create_type ( - ''rel_constraint'', - ''#acs-kernel.lt_Relational_Constraint#'', - ''#acs-kernel.lt_Relational_Constraint_1#'', - ''acs_object'', - ''rel_constraints'', - ''constraint_id'', - ''rel_constraint'', - ''f'', + 'rel_constraint', + '#acs-kernel.lt_Relational_Constraint#', + '#acs-kernel.lt_Relational_Constraint_1#', + 'acs_object', + 'rel_constraints', + 'constraint_id', + 'rel_constraint', + 'f', null, null ); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select inline_0 (); @@ -496,10 +496,17 @@ create index rc_segment_required_seg_idx on rc_segment_required_seg_map(required_rel_segment); -create function rel_constraints_ins_tr () returns trigger as ' -declare + + +-- +-- procedure rel_constraints_ins_tr/0 +-- +CREATE OR REPLACE FUNCTION rel_constraints_ins_tr( + +) RETURNS trigger AS $$ +DECLARE v_rec record; -begin +BEGIN -- insert the constraint insert into rc_segment_required_seg_map @@ -533,16 +540,24 @@ return new; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; create trigger rel_constraints_ins_tr after insert on rel_constraints for each row execute procedure rel_constraints_ins_tr (); -create function rel_constraints_del_tr () returns trigger as ' -declare + + +-- +-- procedure rel_constraints_del_tr/0 +-- +CREATE OR REPLACE FUNCTION rel_constraints_del_tr( + +) RETURNS trigger AS $$ +DECLARE v_rec record; -begin +BEGIN -- now update the rel_segments that depend on this segment @@ -583,7 +598,8 @@ return old; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; create trigger rel_constraints_del_tr after delete on rel_constraints for each row Index: openacs-4/packages/acs-kernel/sql/postgresql/rel-constraints-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/postgresql/rel-constraints-drop.sql,v diff -u -r1.2 -r1.3 --- openacs-4/packages/acs-kernel/sql/postgresql/rel-constraints-drop.sql 18 Jun 2004 18:21:57 -0000 1.2 +++ openacs-4/packages/acs-kernel/sql/postgresql/rel-constraints-drop.sql 7 Jul 2011 10:46:02 -0000 1.3 @@ -5,11 +5,12 @@ -- @creation-date 2000-11-22 -- @cvs-id $Id$ \t -create function inline_0 () returns integer as ' -begin - PERFORM acs_rel_type__drop_type(''rel_constraint''); +CREATE OR REPLACE FUNCTION inline_0 () RETURNS integer AS $$ +BEGIN + PERFORM acs_rel_type__drop_type('rel_constraint'); return null; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select inline_0 (); drop function inline_0 (); Index: openacs-4/packages/acs-kernel/sql/postgresql/rel-segments-body-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/postgresql/rel-segments-body-create.sql,v diff -u -r1.15 -r1.16 --- openacs-4/packages/acs-kernel/sql/postgresql/rel-segments-body-create.sql 18 Jun 2004 18:21:57 -0000 1.15 +++ openacs-4/packages/acs-kernel/sql/postgresql/rel-segments-body-create.sql 7 Jul 2011 10:46:02 -0000 1.16 @@ -15,22 +15,31 @@ ------------------ -- rel_segment__new -- full version -create or replace function rel_segment__new (integer,varchar,timestamptz,integer,varchar,varchar,varchar,varchar,integer,varchar,integer) -returns integer as ' -declare - new__segment_id alias for $1; -- default null - object_type alias for $2; -- default ''rel_segment'' - creation_date alias for $3; -- default now() - creation_user alias for $4; -- default null - creation_ip alias for $5; -- default null - email alias for $6; -- default null - url alias for $7; -- default null - new__segment_name alias for $8; - new__group_id alias for $9; - new__rel_type alias for $10; - context_id alias for $11; -- default null + + +-- added +select define_function_args('rel_segment__new','segment_id;null,object_type;rel_segment,creation_date;now(),creation_user;null,creation_ip;null,email;null,url;null,segment_name,group_id,rel_type,context_id;null'); + +-- +-- procedure rel_segment__new/11 +-- +CREATE OR REPLACE FUNCTION rel_segment__new( + new__segment_id integer, -- default null + object_type varchar, -- default 'rel_segment' + creation_date timestamptz, -- default now() + creation_user integer, -- default null + creation_ip varchar, -- default null + email varchar, -- default null + url varchar, -- default null + new__segment_name varchar, + new__group_id integer, + new__rel_type varchar, + context_id integer -- default null + +) RETURNS integer AS $$ +DECLARE v_segment_id rel_segments.segment_id%TYPE; -begin +BEGIN v_segment_id := party__new(new__segment_id, object_type, creation_date, creation_user, creation_ip, email, url, context_id); @@ -46,32 +55,47 @@ return v_segment_id; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- rel_segment__new -- overloaded version for specifying only non-default values -create or replace function rel_segment__new (varchar,integer,varchar) -returns integer as ' -declare - new__segment_name alias for $1; - new__group_id alias for $2; - new__rel_type alias for $3; + + +-- +-- procedure rel_segment__new/3 +-- +CREATE OR REPLACE FUNCTION rel_segment__new( + new__segment_name varchar, + new__group_id integer, + new__rel_type varchar +) RETURNS integer AS $$ +DECLARE v_segment_id rel_segments.segment_id%TYPE; -begin +BEGIN - v_segment_id := rel_segment__new(null, ''rel_segment'', now(), null, null, null, null, new__segment_name, new__group_id, new__rel_type, null); + v_segment_id := rel_segment__new(null, 'rel_segment', now(), null, null, null, null, new__segment_name, new__group_id, new__rel_type, null); return v_segment_id; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure delete -create or replace function rel_segment__delete (integer) -returns integer as ' -declare - delete__segment_id alias for $1; + + +-- added +select define_function_args('rel_segment__delete','segment_id'); + +-- +-- procedure rel_segment__delete/1 +-- +CREATE OR REPLACE FUNCTION rel_segment__delete( + delete__segment_id integer +) RETURNS integer AS $$ +DECLARE row record; -begin +BEGIN -- remove all constraints on this segment for row in select constraint_id @@ -86,42 +110,70 @@ PERFORM party__delete(delete__segment_id); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function get -create or replace function rel_segment__get (integer,varchar) -returns integer as ' -declare - get__group_id alias for $1; - get__rel_type alias for $2; -begin + +-- added +select define_function_args('rel_segment__get','group_id,rel_type'); + +-- +-- procedure rel_segment__get/2 +-- +CREATE OR REPLACE FUNCTION rel_segment__get( + get__group_id integer, + get__rel_type varchar +) RETURNS integer AS $$ +DECLARE +BEGIN + return min(segment_id) from rel_segments where group_id = get__group_id and rel_type = get__rel_type; -end;' language 'plpgsql' stable strict; +END; +$$ LANGUAGE plpgsql stable strict; -create or replace function rel_segment__get_or_new(integer,varchar) returns integer as ' -declare - gid alias for $1; - typ alias for $2; -begin + + +-- added + +-- +-- procedure rel_segment__get_or_new/2 +-- +CREATE OR REPLACE FUNCTION rel_segment__get_or_new( + gid integer, + typ varchar +) RETURNS integer AS $$ +DECLARE +BEGIN return rel_segment__get_or_new(gid,typ,null); -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function get_or_new -create or replace function rel_segment__get_or_new (integer,varchar,varchar) -returns integer as ' -declare - get_or_new__group_id alias for $1; - get_or_new__rel_type alias for $2; - segment_name alias for $3; -- default null + + +-- added +select define_function_args('rel_segment__get_or_new','group_id,rel_type,segment_name;null'); + +-- +-- procedure rel_segment__get_or_new/3 +-- +CREATE OR REPLACE FUNCTION rel_segment__get_or_new( + get_or_new__group_id integer, + get_or_new__rel_type varchar, + segment_name varchar -- default null + +) RETURNS integer AS $$ +DECLARE v_segment_id rel_segments.segment_id%TYPE; v_segment_name rel_segments.segment_name%TYPE; -begin +BEGIN v_segment_id := rel_segment__get(get_or_new__group_id,get_or_new__rel_type); @@ -130,8 +182,8 @@ if segment_name is not null then v_segment_name := segment_name; else - select groups.group_name || '' - '' || acs_object_types.pretty_name || - '' segment'' + select groups.group_name || ' - ' || acs_object_types.pretty_name || + ' segment' into v_segment_name from groups, acs_object_types where groups.group_id = get_or_new__group_id @@ -141,7 +193,7 @@ v_segment_id := rel_segment__new ( null, - ''rel_segment'', + 'rel_segment', now(), null, null, @@ -158,21 +210,31 @@ return v_segment_id; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function name -create or replace function rel_segment__name (integer) -returns varchar as ' -declare - name__segment_id alias for $1; + + +-- added +select define_function_args('rel_segment__name','segment_id'); + +-- +-- procedure rel_segment__name/1 +-- +CREATE OR REPLACE FUNCTION rel_segment__name( + name__segment_id integer +) RETURNS varchar AS $$ +DECLARE name__segment_name varchar(200); -begin +BEGIN return segment_name from rel_segments where segment_id = name__segment_id; -end;' language 'plpgsql' stable strict; +END; +$$ LANGUAGE plpgsql stable strict; Index: openacs-4/packages/acs-kernel/sql/postgresql/rel-segments-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/postgresql/rel-segments-create.sql,v diff -u -r1.14 -r1.15 --- openacs-4/packages/acs-kernel/sql/postgresql/rel-segments-create.sql 10 Mar 2010 00:44:03 -0000 1.14 +++ openacs-4/packages/acs-kernel/sql/postgresql/rel-segments-create.sql 7 Jul 2011 10:46:02 -0000 1.15 @@ -15,29 +15,29 @@ -- change in the future, particularly the functions marked "EXPERIMENTAL". -- -create function inline_0 () -returns integer as ' -begin +CREATE OR REPLACE FUNCTION inline_0 () RETURNS integer AS $$ +BEGIN -- -- Relational Segment: a dynamically derived set of parties, defined -- in terms of a particular type of membership or -- composition to a particular group. -- PERFORM acs_object_type__create_type ( - ''rel_segment'', - ''#acs-kernel.lt_Relational_Party_Segm#'', - ''#acs-kernel.lt_Relational_Party_Segm_1#'', - ''party'', - ''rel_segments'', - ''segment_id'', - ''rel_segment'', - ''f'', + 'rel_segment', + '#acs-kernel.lt_Relational_Party_Segm#', + '#acs-kernel.lt_Relational_Party_Segm_1#', + 'party', + 'rel_segments', + 'segment_id', + 'rel_segment', + 'f', null, - ''rel_segment__name'' + 'rel_segment__name' ); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select inline_0 (); @@ -182,30 +182,49 @@ -- Helper functions to maintain the materialized party_approved_member_map. -create or replace function party_approved_member__add_one(integer, integer, integer) returns integer as ' -declare - p_party_id alias for $1; - p_member_id alias for $2; - p_rel_id alias for $3; -begin + +-- added +select define_function_args('party_approved_member__add_one','party_id,member_id,rel_id'); + +-- +-- procedure party_approved_member__add_one/3 +-- +CREATE OR REPLACE FUNCTION party_approved_member__add_one( + p_party_id integer, + p_member_id integer, + p_rel_id integer +) RETURNS integer AS $$ +DECLARE +BEGIN + insert into party_approved_member_map (party_id, member_id, tag) values (p_party_id, p_member_id, p_rel_id); return 1; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create or replace function party_approved_member__add(integer, integer, integer, varchar) returns integer as ' -declare - p_party_id alias for $1; - p_member_id alias for $2; - p_rel_id alias for $3; - p_rel_type alias for $4; + + +-- added +select define_function_args('party_approved_member__add','party_id,member_id,rel_id,rel_type'); + +-- +-- procedure party_approved_member__add/4 +-- +CREATE OR REPLACE FUNCTION party_approved_member__add( + p_party_id integer, + p_member_id integer, + p_rel_id integer, + p_rel_type varchar +) RETURNS integer AS $$ +DECLARE v_segments record; -begin +BEGIN perform party_approved_member__add_one(p_party_id, p_member_id, p_rel_id); @@ -224,33 +243,53 @@ return 1; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create or replace function party_approved_member__remove_one(integer, integer, integer) returns integer as ' -declare - p_party_id alias for $1; - p_member_id alias for $2; - p_rel_id alias for $3; -begin + +-- added +select define_function_args('party_approved_member__remove_one','party_id,member_id,rel_id'); + +-- +-- procedure party_approved_member__remove_one/3 +-- +CREATE OR REPLACE FUNCTION party_approved_member__remove_one( + p_party_id integer, + p_member_id integer, + p_rel_id integer +) RETURNS integer AS $$ +DECLARE +BEGIN + delete from party_approved_member_map where party_id = p_party_id and member_id = p_member_id and tag = p_rel_id; return 1; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create or replace function party_approved_member__remove(integer, integer, integer, varchar) returns integer as ' -declare - p_party_id alias for $1; - p_member_id alias for $2; - p_rel_id alias for $3; - p_rel_type alias for $4; + + +-- added +select define_function_args('party_approved_member__remove','party_id,member_id,rel_id,rel_type'); + +-- +-- procedure party_approved_member__remove/4 +-- +CREATE OR REPLACE FUNCTION party_approved_member__remove( + p_party_id integer, + p_member_id integer, + p_rel_id integer, + p_rel_type varchar +) RETURNS integer AS $$ +DECLARE v_segments record; -begin +BEGIN perform party_approved_member__remove_one(p_party_id, p_member_id, p_rel_id); @@ -269,15 +308,16 @@ return 1; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- Triggers to maintain party_approved_member_map when parties are created or -- destroyed. These don't call the above helper functions because we're just -- creating the identity row for the party. -create or replace function parties_in_tr () returns trigger as ' -begin +CREATE OR REPLACE FUNCTION parties_in_tr () RETURNS trigger AS $$ +BEGIN insert into party_approved_member_map (party_id, member_id, tag) @@ -286,21 +326,23 @@ return new; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; create trigger parties_in_tr after insert on parties for each row execute procedure parties_in_tr (); -create or replace function parties_del_tr () returns trigger as ' -begin +CREATE OR REPLACE FUNCTION parties_del_tr () RETURNS trigger AS $$ +BEGIN delete from party_approved_member_map where party_id = old.party_id and member_id = old.party_id; return old; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; create trigger parties_del_tr before delete on parties for each row execute procedure parties_del_tr (); @@ -311,8 +353,8 @@ -- group with that rel_type. This was intentional on the part of the aD folks -- who added relational segments to ACS 4.2. -create or replace function rel_segments_in_tr () returns trigger as ' -begin +CREATE OR REPLACE FUNCTION rel_segments_in_tr () RETURNS trigger AS $$ +BEGIN insert into party_approved_member_map (party_id, member_id, tag) @@ -323,13 +365,14 @@ return new; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; create trigger rel_segments_in_tr before insert on rel_segments for each row execute procedure rel_segments_in_tr (); -create or replace function rel_segments_del_tr () returns trigger as ' -begin +CREATE OR REPLACE FUNCTION rel_segments_del_tr () RETURNS trigger AS $$ +BEGIN delete from party_approved_member_map where party_id = old.segment_id @@ -340,7 +383,8 @@ return old; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; create trigger rel_segments_del_tr before delete on rel_segments for each row execute procedure rel_segments_del_tr (); Index: openacs-4/packages/acs-kernel/sql/postgresql/rel-segments-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/postgresql/rel-segments-drop.sql,v diff -u -r1.5 -r1.6 --- openacs-4/packages/acs-kernel/sql/postgresql/rel-segments-drop.sql 18 Jun 2004 18:21:57 -0000 1.5 +++ openacs-4/packages/acs-kernel/sql/postgresql/rel-segments-drop.sql 7 Jul 2011 10:46:02 -0000 1.6 @@ -14,9 +14,10 @@ PERFORM rel_segment__delete(r.segment_id); end loop; - PERFORM acs_object_type__drop_type(''rel_segment''); + PERFORM acs_object_type__drop_type('rel_segment'); return null; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select inline_0 (); drop view party_element_map; Index: openacs-4/packages/acs-kernel/sql/postgresql/site-node-object-map-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/postgresql/site-node-object-map-create.sql,v diff -u -r1.5 -r1.6 --- openacs-4/packages/acs-kernel/sql/postgresql/site-node-object-map-create.sql 7 Jun 2008 20:28:52 -0000 1.5 +++ openacs-4/packages/acs-kernel/sql/postgresql/site-node-object-map-create.sql 7 Jul 2011 10:46:02 -0000 1.6 @@ -24,12 +24,17 @@ select define_function_args('site_node_object_map__new', 'object_id,node_id'); -create function site_node_object_map__new (integer,integer) -returns integer as ' -declare - p_object_id alias for $1; - p_node_id alias for $2; -begin + + +-- +-- procedure site_node_object_map__new/2 +-- +CREATE OR REPLACE FUNCTION site_node_object_map__new( + p_object_id integer, + p_node_id integer +) RETURNS integer AS $$ +DECLARE +BEGIN perform site_node_object_map__del(p_object_id); insert @@ -39,20 +44,27 @@ (p_object_id, p_node_id); return 0; -end; -' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; + select define_function_args('site_node_object_map__del', 'object_id'); -create function site_node_object_map__del (integer) -returns integer as ' -declare - p_object_id alias for $1; -begin + + +-- +-- procedure site_node_object_map__del/1 +-- +CREATE OR REPLACE FUNCTION site_node_object_map__del( + p_object_id integer +) RETURNS integer AS $$ +DECLARE +BEGIN delete from site_node_object_mappings where object_id = p_object_id; return 0; -end; -' language 'plpgsql'; +END; + +$$ LANGUAGE plpgsql; Index: openacs-4/packages/acs-kernel/sql/postgresql/site-nodes-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/postgresql/site-nodes-create.sql,v diff -u -r1.24 -r1.25 --- openacs-4/packages/acs-kernel/sql/postgresql/site-nodes-create.sql 24 Nov 2010 18:58:45 -0000 1.24 +++ openacs-4/packages/acs-kernel/sql/postgresql/site-nodes-create.sql 7 Jul 2011 10:46:02 -0000 1.25 @@ -6,26 +6,33 @@ -- @cvs-id $Id$ -- -create or replace function inline_0 () -returns integer as ' -declare + + +-- +-- procedure inline_0/0 +-- +CREATE OR REPLACE FUNCTION inline_0( + +) RETURNS integer AS $$ +DECLARE dummy integer; -begin +BEGIN PERFORM acs_object_type__create_type ( - ''site_node'', - ''Site Node'', - ''Site Nodes'', - ''acs_object'', - ''site_nodes'', - ''node_id'', - ''site_node'', - ''f'', + 'site_node', + 'Site Node', + 'Site Nodes', + 'acs_object', + 'site_nodes', + 'node_id', + 'site_node', + 'f', null, null ); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select inline_0 (); @@ -62,18 +69,35 @@ create index site_nodes_parent_id_idx on site_nodes(parent_id,object_id,node_id); create index site_nodes_tree_skey_idx on site_nodes (tree_sortkey); -create or replace function site_node_get_tree_sortkey(integer) returns varbit as ' -declare - p_node_id alias for $1; -begin + + +-- added +select define_function_args('site_node_get_tree_sortkey','node_id'); + +-- +-- procedure site_node_get_tree_sortkey/1 +-- +CREATE OR REPLACE FUNCTION site_node_get_tree_sortkey( + p_node_id integer +) RETURNS varbit AS $$ +DECLARE +BEGIN return tree_sortkey from site_nodes where node_id = p_node_id; -end;' language 'plpgsql' stable strict; +END; +$$ LANGUAGE plpgsql stable strict; -create or replace function site_node_insert_tr () returns trigger as ' -declare + + +-- +-- procedure site_node_insert_tr/0 +-- +CREATE OR REPLACE FUNCTION site_node_insert_tr( + +) RETURNS trigger AS $$ +DECLARE v_parent_sk varbit default null; v_max_value integer; -begin +BEGIN if new.parent_id is null then select max(tree_leaf_key_to_int(tree_sortkey)) into v_max_value from site_nodes @@ -92,20 +116,28 @@ return new; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; create trigger site_node_insert_tr before insert on site_nodes for each row execute procedure site_node_insert_tr (); -create or replace function site_node_update_tr () returns trigger as ' -declare + + +-- +-- procedure site_node_update_tr/0 +-- +CREATE OR REPLACE FUNCTION site_node_update_tr( + +) RETURNS trigger AS $$ +DECLARE v_parent_sk varbit default null; v_max_value integer; p_id integer; v_rec record; - clr_keys_p boolean default ''t''; -begin + clr_keys_p boolean default 't'; +BEGIN if new.node_id = old.node_id and ((new.parent_id = old.parent_id) or (new.parent_id is null and old.parent_id is null)) then @@ -122,7 +154,7 @@ if clr_keys_p then update site_nodes set tree_sortkey = null where tree_sortkey between new.tree_sortkey and tree_right(new.tree_sortkey); - clr_keys_p := ''f''; + clr_keys_p := 'f'; end if; select parent_id into p_id @@ -151,7 +183,8 @@ return new; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; create trigger site_node_update_tr after update on site_nodes @@ -203,40 +236,50 @@ -- show errors -select define_function_args ('site_node__new', 'node_id,parent_id,name,object_id,directory_p,pattern_p,creation_user,creation_ip'); -create or replace function site_node__new (integer,integer,varchar,integer,boolean,boolean,integer,varchar) -returns integer as ' -declare - new__node_id alias for $1; -- default null - new__parent_id alias for $2; -- default null - new__name alias for $3; - new__object_id alias for $4; -- default null - new__directory_p alias for $5; - new__pattern_p alias for $6; -- default ''f'' - new__creation_user alias for $7; -- default null - new__creation_ip alias for $8; -- default null +-- old define_function_args ('site_node__new', 'node_id,parent_id,name,object_id,directory_p,pattern_p,creation_user,creation_ip') +-- new +select define_function_args('site_node__new','node_id;null,parent_id;null,name,object_id;null,directory_p,pattern_p;f,creation_user;null,creation_ip;null'); + + + + +-- +-- procedure site_node__new/8 +-- +CREATE OR REPLACE FUNCTION site_node__new( + new__node_id integer, -- default null + new__parent_id integer, -- default null + new__name varchar, + new__object_id integer, -- default null + new__directory_p boolean, + new__pattern_p boolean, -- default 'f' + new__creation_user integer, -- default null + new__creation_ip varchar -- default null + +) RETURNS integer AS $$ +DECLARE v_node_id site_nodes.node_id%TYPE; v_directory_p site_nodes.directory_p%TYPE; -begin +BEGIN if new__parent_id is not null then select directory_p into v_directory_p from site_nodes where node_id = new__parent_id; - if v_directory_p = ''f'' then - raise EXCEPTION ''-20000: Node % is not a directory'', new__parent_id; + if v_directory_p = 'f' then + raise EXCEPTION '-20000: Node % is not a directory', new__parent_id; end if; end if; v_node_id := acs_object__new ( new__node_id, - ''site_node'', + 'site_node', now(), new__creation_user, new__creation_ip, null, - ''t'', + 't', new__name, new__object_id ); @@ -249,56 +292,84 @@ return v_node_id; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure delete -create or replace function site_node__delete (integer) -returns integer as ' -declare - delete__node_id alias for $1; -begin + + +-- added +select define_function_args('site_node__delete','node_id'); + +-- +-- procedure site_node__delete/1 +-- +CREATE OR REPLACE FUNCTION site_node__delete( + delete__node_id integer +) RETURNS integer AS $$ +DECLARE +BEGIN delete from site_nodes where node_id = delete__node_id; PERFORM acs_object__delete(delete__node_id); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function find_pattern -create or replace function site_node__find_pattern (integer) -returns integer as ' -declare - find_pattern__node_id alias for $1; + + +-- added +select define_function_args('site_node__find_pattern','node_id'); + +-- +-- procedure site_node__find_pattern/1 +-- +CREATE OR REPLACE FUNCTION site_node__find_pattern( + find_pattern__node_id integer +) RETURNS integer AS $$ +DECLARE v_pattern_p site_nodes.pattern_p%TYPE; v_parent_id site_nodes.node_id%TYPE; -begin +BEGIN if find_pattern__node_id is null then -- raise no_data_found; - raise exception ''NO DATA FOUND''; + raise exception 'NO DATA FOUND'; end if; select pattern_p, parent_id into v_pattern_p, v_parent_id from site_nodes where node_id = find_pattern__node_id; - if v_pattern_p = ''t'' then + if v_pattern_p = 't' then return find_pattern__node_id; else return site_node__find_pattern(v_parent_id); end if; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function node_id -create or replace function site_node__node_id (varchar,integer) -returns integer as ' -declare - node_id__url alias for $1; - node_id__parent_id alias for $2; -- default null + + +-- added +select define_function_args('site_node__node_id','url,parent_id;null'); + +-- +-- procedure site_node__node_id/2 +-- +CREATE OR REPLACE FUNCTION site_node__node_id( + node_id__url varchar, + node_id__parent_id integer -- default null + +) RETURNS integer AS $$ +DECLARE v_pos integer; v_first site_nodes.name%TYPE; v_rest text; @@ -307,18 +378,18 @@ v_url text; v_directory_p site_nodes.directory_p%TYPE; v_trailing_slash_p boolean; -begin +BEGIN v_url := node_id__url; - if substr(v_url, length(v_url), 1) = ''/'' then + if substr(v_url, length(v_url), 1) = '/' then -- It ends with a / so it must be a directory. - v_trailing_slash_p := ''t''; + v_trailing_slash_p := 't'; v_url := substr(v_url, 1, length(v_url) - 1); end if; v_pos := 1; - while v_pos <= length(v_url) and substr(v_url, v_pos, 1) <> ''/'' loop + while v_pos <= length(v_url) and substr(v_url, v_pos, 1) <> '/' loop v_pos := v_pos + 1; end loop; @@ -347,7 +418,7 @@ end if; if v_rest is null then - if v_trailing_slash_p = ''t'' and v_directory_p = ''f'' then + if v_trailing_slash_p = 't' and v_directory_p = 'f' then return site_node__find_pattern(node_id__parent_id); else return v_node_id; @@ -357,34 +428,44 @@ end if; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- function url -create or replace function site_node__url (integer) -returns varchar as ' -declare - url__node_id alias for $1; + + +-- added +select define_function_args('site_node__url','node_id'); + +-- +-- procedure site_node__url/1 +-- +CREATE OR REPLACE FUNCTION site_node__url( + url__node_id integer +) RETURNS varchar AS $$ +DECLARE v_parent_id site_nodes.node_id%TYPE; v_name site_nodes.name%TYPE; v_directory_p site_nodes.directory_p%TYPE; -begin +BEGIN if url__node_id is null then - return ''''; + return ''; end if; select parent_id, name, directory_p into v_parent_id, v_name, v_directory_p from site_nodes where node_id = url__node_id; - if v_directory_p = ''t'' then - return site_node__url(v_parent_id) || v_name || ''/''; + if v_directory_p = 't' then + return site_node__url(v_parent_id) || v_name || '/'; else return site_node__url(v_parent_id) || v_name; end if; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; Index: openacs-4/packages/acs-kernel/sql/postgresql/site-nodes-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/postgresql/site-nodes-drop.sql,v diff -u -r1.2 -r1.3 --- openacs-4/packages/acs-kernel/sql/postgresql/site-nodes-drop.sql 18 Jun 2004 18:21:57 -0000 1.2 +++ openacs-4/packages/acs-kernel/sql/postgresql/site-nodes-drop.sql 7 Jul 2011 10:46:02 -0000 1.3 @@ -10,11 +10,12 @@ select drop_package('site_node'); drop table site_nodes; -create function inline_0 () returns integer as ' -begin - PERFORM acs_object_type__drop_type (''site_node''); +CREATE OR REPLACE FUNCTION inline_0 () RETURNS integer AS $$ +BEGIN + PERFORM acs_object_type__drop_type ('site_node'); returns null; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select inline_0 (); drop function inline_0 (); \t Index: openacs-4/packages/acs-kernel/sql/postgresql/utilities-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/postgresql/utilities-create.sql,v diff -u -r1.6 -r1.7 --- openacs-4/packages/acs-kernel/sql/postgresql/utilities-create.sql 8 Jun 2006 23:38:27 -0000 1.6 +++ openacs-4/packages/acs-kernel/sql/postgresql/utilities-create.sql 7 Jul 2011 10:46:02 -0000 1.7 @@ -8,37 +8,56 @@ -- @cvs-id $Id$ -- -create function util__multiple_nextval (varchar,integer) -returns varchar as ' -declare - v_sequence_name alias for $1; - v_count alias for $2; - a_sequence_values text default ''''; + + +-- added +select define_function_args('util__multiple_nextval','v_sequence_name,v_count'); + +-- +-- procedure util__multiple_nextval/2 +-- +CREATE OR REPLACE FUNCTION util__multiple_nextval( + v_sequence_name varchar, + v_count integer +) RETURNS varchar AS $$ +DECLARE + a_sequence_values text default ''; v_rec record; -begin +BEGIN for counter in 1..v_count loop - for v_rec in EXECUTE ''select '' || quote_ident(v_sequence_name) || ''.nextval as a_seq_val'' + for v_rec in EXECUTE 'select ' || quote_ident(v_sequence_name) || '.nextval as a_seq_val' LOOP - a_sequence_values := a_sequence_values || '''','''' || v_rec.a_seq_val; + a_sequence_values := a_sequence_values || '','' || v_rec.a_seq_val; exit; end loop; end loop; return substr(a_sequence_values, 2); -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create function util__logical_negation (boolean) returns boolean as ' -declare - true_or_false alias for $1; -begin + + +-- added +select define_function_args('util__logical_negation','true_or_false'); + +-- +-- procedure util__logical_negation/1 +-- +CREATE OR REPLACE FUNCTION util__logical_negation( + true_or_false boolean +) RETURNS boolean AS $$ +DECLARE +BEGIN IF true_or_false is null THEN return null; - ELSE IF true_or_false = ''f'' THEN - return ''t''; + ELSE IF true_or_false = 'f' THEN + return 't'; ELSE - return ''f''; + return 'f'; END IF; END IF; -END;' language 'plpgsql' immutable strict; +END; +$$ LANGUAGE plpgsql immutable strict; Index: openacs-4/packages/acs-kernel/sql/postgresql/test/acs-objects-test.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/postgresql/test/acs-objects-test.sql,v diff -u -r1.2 -r1.3 --- openacs-4/packages/acs-kernel/sql/postgresql/test/acs-objects-test.sql 23 Mar 2001 00:21:50 -0000 1.2 +++ openacs-4/packages/acs-kernel/sql/postgresql/test/acs-objects-test.sql 7 Jul 2011 10:46:02 -0000 1.3 @@ -72,22 +72,29 @@ -- create or replace package body ut#acs_object -- as -create function ut_acs_object__setup() returns integer as ' -declare + + +-- +-- procedure ut_acs_object__setup/0 +-- +CREATE OR REPLACE FUNCTION ut_acs_object__setup( + +) RETURNS integer AS $$ +DECLARE attr_id acs_attributes.attribute_id%TYPE; -begin - raise NOTICE ''Setting up...''; +BEGIN + raise NOTICE 'Setting up...'; -- create the test_object type PERFORM acs_object_type__create_type ( - ''test_object'', - ''Test Object'', - ''Test Objects'', - ''acs_object'', - ''test_objects'', - ''test_id'', + 'test_object', + 'Test Object', + 'Test Objects', + 'acs_object', + 'test_objects', + 'test_id', null, - ''f'', + 'f', null, null ); @@ -96,71 +103,80 @@ insert into acs_object_type_tables (object_type, table_name, id_column) values - (''test_object'',''test_objects'',''test_id''); + ('test_object','test_objects','test_id'); -- create the attribute attr_id := acs_attribute__create_attribute ( - ''test_object'', - ''data'', - ''string'', - ''Data'', - ''Mo Data'', - ''test_objects'', - ''data'', + 'test_object', + 'data', + 'string', + 'Data', + 'Mo Data', + 'test_objects', + 'data', null, 0, 1, null, - ''type_specific'', - ''f'' + 'type_specific', + 'f' ); return null; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create function ut_acs_object__teardown() returns integer as ' -begin - raise NOTICE ''Tearing down...''; +CREATE OR REPLACE FUNCTION ut_acs_object__teardown() RETURNS integer AS $$ +BEGIN + raise NOTICE 'Tearing down...'; -- delete the test object - delete from acs_attributes where object_type = ''test_object''; - delete from acs_object_type_tables where object_type = ''test_object''; - delete from acs_objects where object_type = ''test_object''; + delete from acs_attributes where object_type = 'test_object'; + delete from acs_object_type_tables where object_type = 'test_object'; + delete from acs_objects where object_type = 'test_object'; drop table test_objects; -- clean out the test data drop table ut_acs_objects; -- delete the object_type - delete from acs_object_types where object_type = ''test_object''; + delete from acs_object_types where object_type = 'test_object'; return null; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create function ut_acs_object__new() returns integer as ' -declare + + +-- +-- procedure ut_acs_object__new/0 +-- +CREATE OR REPLACE FUNCTION ut_acs_object__new( + +) RETURNS integer AS $$ +DECLARE result boolean; -begin - raise NOTICE ''Testing new...''; +BEGIN + raise NOTICE 'Testing new...'; -- Tests just the common functionality of the API. - if acs_object__new(-1000, ''test_object'') <> -1000 then - raise NOTICE ''Creating a new test object failed''; + if acs_object__new(-1000, 'test_object') <> -1000 then + raise NOTICE 'Creating a new test object failed'; end if; -- create a new object to delete; note that this test assumes that -- the .new operator works. - if acs_object__new(-1001, ''test_object'') <> -1001 then - raise NOTICE ''Creating a new test object failed''; + if acs_object__new(-1001, 'test_object') <> -1001 then + raise NOTICE 'Creating a new test object failed'; end if; - if acs_object__new(-1003, ''test_object'') <> -1003 then - raise NOTICE ''Creating a new test object failed''; + if acs_object__new(-1003, 'test_object') <> -1003 then + raise NOTICE 'Creating a new test object failed'; end if; -- create an object @@ -169,28 +185,36 @@ (object_id, object_type, creation_date, security_inherit_p, last_modified) values - (-1000, ''test_object'', now(), ''t'', now()); + (-1000, 'test_object', now(), 't', now()); -- Verify that the API does the correct insert. - select ''t'' into result + select 't' into result from ut_acs_objects uo, acs_objects o where uo.object_id = o.object_id and uo.object_id = -1000; if NOT FOUND then - raise NOTICE ''Comparing created data for object failed''; + raise NOTICE 'Comparing created data for object failed'; end if; return null; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create function ut_acs_object__delete() returns integer as ' -declare + + +-- +-- procedure ut_acs_object__delete/0 +-- +CREATE OR REPLACE FUNCTION ut_acs_object__delete( + +) RETURNS integer AS $$ +DECLARE v_rec record; -begin - raise NOTICE ''Testing delete...''; +BEGIN + raise NOTICE 'Testing delete...'; -- delete the row. PERFORM acs_object__delete(-1001); @@ -201,48 +225,58 @@ from acs_objects where object_id = -1001; if FOUND then - raise NOTICE ''Delete verification failed''; + raise NOTICE 'Delete verification failed'; end if; return null; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create function ut_acs_object__name() returns integer as ' -begin - raise NOTICE ''Testing name...''; +CREATE OR REPLACE FUNCTION ut_acs_object__name() RETURNS integer AS $$ +BEGIN + raise NOTICE 'Testing name...'; - if acs_object__name(-1001) <> ''Test Object -1000'' then - raise NOTICE ''Creating a name failed''; + if acs_object__name(-1001) <> 'Test Object -1000' then + raise NOTICE 'Creating a name failed'; end if; return null; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create function ut_acs_object__default_name() returns integer as ' -begin - raise NOTICE ''Testing default_name...''; +CREATE OR REPLACE FUNCTION ut_acs_object__default_name() RETURNS integer AS $$ +BEGIN + raise NOTICE 'Testing default_name...'; - if acs_object__default_name(-1001) <> ''Test Object -1000'' then - raise NOTICE ''Creating a default name failed''; + if acs_object__default_name(-1001) <> 'Test Object -1000' then + raise NOTICE 'Creating a default name failed'; end if; return null; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create function ut_acs_object__set_attribute() returns integer as ' -declare + + +-- +-- procedure ut_acs_object__set_attribute/0 +-- +CREATE OR REPLACE FUNCTION ut_acs_object__set_attribute( + +) RETURNS integer AS $$ +DECLARE v_sql_result test_objects.data%TYPE; -begin - raise NOTICE ''Testing set_attribute''; +BEGIN + raise NOTICE 'Testing set_attribute'; -- since we did not create a test object new constructor -- were going to insert into attributes here. insert into test_objects(test_id) values(-1003); - PERFORM acs_object__set_attribute(-1003, ''data'', ''2702''); + PERFORM acs_object__set_attribute(-1003, 'data', '2702'); -- since utassert is not powerful enough right now, we do this -- comparison manually @@ -251,37 +285,46 @@ where test_id = -1003; if v_sql_result = 2702 then - raise NOTICE ''SUCCESS: set_attribute''; + raise NOTICE 'SUCCESS: set_attribute'; else - raise NOTICE ''Verifying attribute data FAILED''; + raise NOTICE 'Verifying attribute data FAILED'; end if; return null; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create function ut_acs_object__get_attribute() returns integer as ' -declare + + +-- +-- procedure ut_acs_object__get_attribute/0 +-- +CREATE OR REPLACE FUNCTION ut_acs_object__get_attribute( + +) RETURNS integer AS $$ +DECLARE v_attr_value varchar(4000); -begin - raise NOTICE ''Testing get_attribute''; +BEGIN + raise NOTICE 'Testing get_attribute'; -- we assume that set attribute works. since im lazy -- im going to recycle the -1003 object. - PERFORM acs_object__set_attribute(-1003, ''data'', ''sugarwen''); + PERFORM acs_object__set_attribute(-1003, 'data', 'sugarwen'); - v_attr_value := acs_object__get_attribute(-1003, ''data''); + v_attr_value := acs_object__get_attribute(-1003, 'data'); - if v_attr_value = ''sugarwen'' then - raise NOTICE ''SUCCESS: get_attribute''; + if v_attr_value = 'sugarwen' then + raise NOTICE 'SUCCESS: get_attribute'; else - raise NOTICE ''Verifying get attribute data FAILED''; + raise NOTICE 'Verifying get attribute data FAILED'; end if; return null; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; create table test_objects ( test_id integer primary key, Index: openacs-4/packages/acs-kernel/sql/postgresql/test/groups-test.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/postgresql/test/groups-test.sql,v diff -u -r1.1 -r1.2 --- openacs-4/packages/acs-kernel/sql/postgresql/test/groups-test.sql 22 Mar 2001 00:21:19 -0000 1.1 +++ openacs-4/packages/acs-kernel/sql/postgresql/test/groups-test.sql 7 Jul 2011 10:46:02 -0000 1.2 @@ -20,8 +20,15 @@ uname varchar(100) ); -create function test_groups() returns integer as ' -declare + + +-- +-- procedure test_groups/0 +-- +CREATE OR REPLACE FUNCTION test_groups( + +) RETURNS integer AS $$ +DECLARE A integer; B integer; C integer; @@ -53,51 +60,51 @@ rel_l integer; gp record; n_rows integer; -begin +BEGIN -- Create the test groups. - A := acs_group__new(''A''); - B := acs_group__new(''B''); - C := acs_group__new(''C''); - D := acs_group__new(''D''); - E := acs_group__new(''E''); - F := acs_group__new(''F''); - G := acs_group__new(''G''); + A := acs_group__new('A'); + B := acs_group__new('B'); + C := acs_group__new('C'); + D := acs_group__new('D'); + E := acs_group__new('E'); + F := acs_group__new('F'); + G := acs_group__new('G'); - insert into groups_test_groups values (A,1,''A''); - insert into groups_test_groups values (B,2,''B''); - insert into groups_test_groups values (C,3,''C''); - insert into groups_test_groups values (D,4,''D''); - insert into groups_test_groups values (E,5,''E''); - insert into groups_test_groups values (F,6,''F''); - insert into groups_test_groups values (G,7,''G''); + insert into groups_test_groups values (A,1,'A'); + insert into groups_test_groups values (B,2,'B'); + insert into groups_test_groups values (C,3,'C'); + insert into groups_test_groups values (D,4,'D'); + insert into groups_test_groups values (E,5,'E'); + insert into groups_test_groups values (F,6,'F'); + insert into groups_test_groups values (G,7,'G'); -- Create the test members. - joe := acs_user__new(''joe@asdf.com'',''Joe'', - ''Smith'',''assword'',''p''); - jane := acs_user__new(''jane@asdf.com'',''Jane'', - ''Smith'',''assword'',''p''); - bob := acs_user__new(''bob@asdf.com'',''Bob'', - ''Smith'',''assword'',''p''); - betty := acs_user__new(''betty@asdf.com'',''Betty'', - ''Smith'',''assword'',''p''); - jack := acs_user__new(''jack@asdf.com'',''Jack'', - ''Smith'',''assword'',''p''); - jill := acs_user__new(''jill@asdf.com'',''Jill'', - ''Smith'',''assword'',''p''); - sven := acs_user__new(''sven@asdf.com'',''Sven'', - ''Smith'',''assword'',''p''); - stacy := acs_user__new(''stacy@asdf.com'',''Stacy'', - ''Smith'',''assword'',''p''); + joe := acs_user__new('joe@asdf.com','Joe', + 'Smith','assword','p'); + jane := acs_user__new('jane@asdf.com','Jane', + 'Smith','assword','p'); + bob := acs_user__new('bob@asdf.com','Bob', + 'Smith','assword','p'); + betty := acs_user__new('betty@asdf.com','Betty', + 'Smith','assword','p'); + jack := acs_user__new('jack@asdf.com','Jack', + 'Smith','assword','p'); + jill := acs_user__new('jill@asdf.com','Jill', + 'Smith','assword','p'); + sven := acs_user__new('sven@asdf.com','Sven', + 'Smith','assword','p'); + stacy := acs_user__new('stacy@asdf.com','Stacy', + 'Smith','assword','p'); - insert into groups_test_users values (joe,1,''joe''); - insert into groups_test_users values (jane,2,''jane''); - insert into groups_test_users values (bob,3,''bob''); - insert into groups_test_users values (betty,4,''betty''); - insert into groups_test_users values (jack,5,''jack''); - insert into groups_test_users values (jill,6,''jill''); - insert into groups_test_users values (sven,7,''sven''); - insert into groups_test_users values (stacy,8,''stacy''); + insert into groups_test_users values (joe,1,'joe'); + insert into groups_test_users values (jane,2,'jane'); + insert into groups_test_users values (bob,3,'bob'); + insert into groups_test_users values (betty,4,'betty'); + insert into groups_test_users values (jack,5,'jack'); + insert into groups_test_users values (jill,6,'jill'); + insert into groups_test_users values (sven,7,'sven'); + insert into groups_test_users values (stacy,8,'stacy'); -- Make a couple of compositions. @@ -121,39 +128,48 @@ return null; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create function check_groups () returns integer as ' -declare + + +-- +-- procedure check_groups/0 +-- +CREATE OR REPLACE FUNCTION check_groups( + +) RETURNS integer AS $$ +DECLARE gp record; v_rec record; -begin +BEGIN for gp in select * from groups order by group_name LOOP if NOT acs_group__check_representation(gp.group_id) then - raise notice ''Group % (%) failed'', gp.group_name, gp.group_id; + raise notice 'Group % (%) failed', gp.group_name, gp.group_id; else - raise notice ''Group % (%) passed'', gp.group_name, gp.group_id; + raise notice 'Group % (%) passed', gp.group_name, gp.group_id; end if; end LOOP; for v_rec in select group_id from groups_test_groups order by sorder desc LOOP - raise notice ''dropping %'', v_rec.group_id; + raise notice 'dropping %', v_rec.group_id; PERFORM acs_group__delete(v_rec.group_id); end LOOP; delete from groups_test_groups; for v_rec in select user_id from groups_test_users order by sorder LOOP - raise notice ''dropping %'', v_rec.user_id; + raise notice 'dropping %', v_rec.user_id; PERFORM acs_user__delete(v_rec.user_id); end LOOP; delete from groups_test_users; return null; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select test_groups(); select check_groups(); Index: openacs-4/packages/acs-kernel/sql/postgresql/test/rel-constraints-test.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/postgresql/test/rel-constraints-test.sql,v diff -u -r1.4 -r1.5 --- openacs-4/packages/acs-kernel/sql/postgresql/test/rel-constraints-test.sql 14 Apr 2001 05:12:22 -0000 1.4 +++ openacs-4/packages/acs-kernel/sql/postgresql/test/rel-constraints-test.sql 7 Jul 2011 10:46:02 -0000 1.5 @@ -25,30 +25,37 @@ sname varchar(100) ); -create function rel_constraint_dump_views() returns integer as ' -declare + + +-- +-- procedure rel_constraint_dump_views/0 +-- +CREATE OR REPLACE FUNCTION rel_constraint_dump_views( + +) RETURNS integer AS $$ +DECLARE r record; str varchar; -begin +BEGIN - raise NOTICE ''Contents of view rel_constraints_violated_one:''; - str := rpad(''constraint_id'', 20) || rpad(''rel_id'', 20) || - rpad(''name(container_id)'',20) || - rpad(''name(party_id)'',20); + raise NOTICE 'Contents of view rel_constraints_violated_one:'; + str := rpad('constraint_id', 20) || rpad('rel_id', 20) || + rpad('name(container_id)',20) || + rpad('name(party_id)',20); - raise NOTICE ''%'', str; + raise NOTICE '%', str; for r in select * from rel_constraints_violated_one LOOP str := rpad(r.constraint_id, 20) || rpad(r.rel_id, 20) || rpad(acs_object__name(r.container_id), 20) || rpad(acs_object__name(r.party_id), 20); - raise NOTICE ''%'', str; + raise NOTICE '%', str; end LOOP; - raise NOTICE ''Contents of view rel_constraints_violated_two:''; + raise NOTICE 'Contents of view rel_constraints_violated_two:'; for r in select * from rel_constraints_violated_two LOOP @@ -57,32 +64,41 @@ rpad(acs_object__name(r.container_id), 20) || rpad(acs_object__name(r.party_id), 20); - raise NOTICE ''%'', str; + raise NOTICE '%', str; end loop; return null; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create function rel_constraint_test_check (integer, char) -returns integer as ' -declare - v_rel_id alias for $1; - expect_violation_p alias for $2; + + +-- added +select define_function_args('rel_constraint_test_check','v_rel_id,expect_violation_p'); + +-- +-- procedure rel_constraint_test_check/2 +-- +CREATE OR REPLACE FUNCTION rel_constraint_test_check( + v_rel_id integer, + expect_violation_p char +) RETURNS integer AS $$ +DECLARE v_violation_msg varchar(4000); v_violation_p char; v_object_id_one integer; v_object_id_two integer; v_rel_type acs_rels.rel_type%TYPE; str varchar; -begin +BEGIN - v_violation_p := ''f''; + v_violation_p := 'f'; v_violation_msg := rel_constraint__violation(v_rel_id); if v_violation_msg is not null then - v_violation_p := ''t''; + v_violation_p := 't'; end if; if v_violation_p::char != expect_violation_p::char then @@ -92,39 +108,47 @@ from acs_rels where rel_id = v_rel_id; - str := ''Relation '' || acs_object__name(v_rel_id) || - '' ('' || v_rel_id || '')'' || - '' failed (violation_p = '' || v_violation_p::varchar - || ''). '' || - ''Rel info: type = '' || v_rel_type || - '', object one = '' || + str := 'Relation ' || acs_object__name(v_rel_id) || + ' (' || v_rel_id || ')' || + ' failed (violation_p = ' || v_violation_p::varchar + || '). ' || + 'Rel info: type = ' || v_rel_type || + ', object one = ' || acs_object__name(v_object_id_one) || - '' ('' || v_object_id_one || '')'' || - '', object two = '' || + ' (' || v_object_id_one || ')' || + ', object two = ' || acs_object__name(v_object_id_two) || - '' ('' || v_object_id_two || '').''; + ' (' || v_object_id_two || ').'; - PERFORM acs_log__error(''rel_constraint_test_check'', str); + PERFORM acs_log__error('rel_constraint_test_check', str); - raise NOTICE ''%'', str; + raise NOTICE '%', str; - raise NOTICE ''Violation Message:''; - raise NOTICE ''%'', v_violation_msg; + raise NOTICE 'Violation Message:'; + raise NOTICE '%', v_violation_msg; else - raise NOTICE ''passed %'', v_rel_id; + raise NOTICE 'passed %', v_rel_id; end if; return null; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- creates blah_member_rel and yippie_member_rel relationships \i rel-segments-test-types-create.sql -create function test_rel_constraints() returns integer as ' -declare + + +-- +-- procedure test_rel_constraints/0 +-- +CREATE OR REPLACE FUNCTION test_rel_constraints( + +) RETURNS integer AS $$ +DECLARE A integer; B integer; C integer; @@ -161,53 +185,53 @@ r record; -begin +BEGIN -- Create the test groups. - A := acs_group__new(''A''); - B := acs_group__new(''B''); - C := acs_group__new(''C''); - D := acs_group__new(''D''); - E := acs_group__new(''E''); - F := acs_group__new(''F''); - G := acs_group__new(''G''); + A := acs_group__new('A'); + B := acs_group__new('B'); + C := acs_group__new('C'); + D := acs_group__new('D'); + E := acs_group__new('E'); + F := acs_group__new('F'); + G := acs_group__new('G'); - insert into groups_test_groups values (A,1,''A''); - insert into groups_test_groups values (B,2,''B''); - insert into groups_test_groups values (C,3,''C''); - insert into groups_test_groups values (D,4,''D''); - insert into groups_test_groups values (E,5,''E''); - insert into groups_test_groups values (F,6,''F''); - insert into groups_test_groups values (G,7,''G''); + insert into groups_test_groups values (A,1,'A'); + insert into groups_test_groups values (B,2,'B'); + insert into groups_test_groups values (C,3,'C'); + insert into groups_test_groups values (D,4,'D'); + insert into groups_test_groups values (E,5,'E'); + insert into groups_test_groups values (F,6,'F'); + insert into groups_test_groups values (G,7,'G'); -- Create the test members. - joe := acs_user__new(''joe@asdf.com'',''Joe'', - ''Smith'',''assword'',''p''); - jane := acs_user__new(''jane@asdf.com'',''Jane'', - ''Smith'',''assword'',''p''); - bob := acs_user__new(''bob@asdf.com'',''Bob'', - ''Smith'',''assword'',''p''); - betty := acs_user__new(''betty@asdf.com'',''Betty'', - ''Smith'',''assword'',''p''); - jack := acs_user__new(''jack@asdf.com'',''Jack'', - ''Smith'',''assword'',''p''); - jill := acs_user__new(''jill@asdf.com'',''Jill'', - ''Smith'',''assword'',''p''); - sven := acs_user__new(''sven@asdf.com'',''Sven'', - ''Smith'',''assword'',''p''); - stacy := acs_user__new(''stacy@asdf.com'',''Stacy'', - ''Smith'',''assword'',''p''); + joe := acs_user__new('joe@asdf.com','Joe', + 'Smith','assword','p'); + jane := acs_user__new('jane@asdf.com','Jane', + 'Smith','assword','p'); + bob := acs_user__new('bob@asdf.com','Bob', + 'Smith','assword','p'); + betty := acs_user__new('betty@asdf.com','Betty', + 'Smith','assword','p'); + jack := acs_user__new('jack@asdf.com','Jack', + 'Smith','assword','p'); + jill := acs_user__new('jill@asdf.com','Jill', + 'Smith','assword','p'); + sven := acs_user__new('sven@asdf.com','Sven', + 'Smith','assword','p'); + stacy := acs_user__new('stacy@asdf.com','Stacy', + 'Smith','assword','p'); - reg_users := acs__magic_object_id(''registered_users''); + reg_users := acs__magic_object_id('registered_users'); - insert into groups_test_users values (joe,1,''joe''); - insert into groups_test_users values (jane,2,''jane''); - insert into groups_test_users values (bob,3,''bob''); - insert into groups_test_users values (betty,4,''betty''); - insert into groups_test_users values (jack,5,''jack''); - insert into groups_test_users values (jill,6,''jill''); - insert into groups_test_users values (sven,7,''sven''); - insert into groups_test_users values (stacy,8,''stacy''); - insert into groups_test_users values (reg_users,9,''reg_users''); + insert into groups_test_users values (joe,1,'joe'); + insert into groups_test_users values (jane,2,'jane'); + insert into groups_test_users values (bob,3,'bob'); + insert into groups_test_users values (betty,4,'betty'); + insert into groups_test_users values (jack,5,'jack'); + insert into groups_test_users values (jill,6,'jill'); + insert into groups_test_users values (sven,7,'sven'); + insert into groups_test_users values (stacy,8,'stacy'); + insert into groups_test_users values (reg_users,9,'reg_users'); -- Make a couple of compositions. @@ -228,14 +252,14 @@ side_two_constraint := rel_constraint__new( null, - ''rel_constraint'', - ''Yippie: side 2 must be a blah of A'', + 'rel_constraint', + 'Yippie: side 2 must be a blah of A', rel_segment__get_or_new(reg_users, - ''yippie_member_rel'', + 'yippie_member_rel', null), - ''two'', + 'two', rel_segment__get_or_new(A, - ''blah_member_rel'', + 'blah_member_rel', null), null, null, @@ -245,33 +269,33 @@ side_one_constraint := rel_constraint__new( null, - ''rel_constraint'', - ''Yippie: side 1 must be a component of E'', + 'rel_constraint', + 'Yippie: side 1 must be a component of E', rel_segment__get_or_new(reg_users, - ''yippie_member_rel'', + 'yippie_member_rel', null), - ''one'', + 'one', rel_segment__get_or_new(E, - ''composition_rel'', + 'composition_rel', null), null, null, null ); - insert into groups_test_segs values (side_two_constraint,1,''side_two_constraint''); - insert into groups_test_segs values (side_one_constraint,2,''side_one_constraint''); + insert into groups_test_segs values (side_two_constraint,1,'side_two_constraint'); + insert into groups_test_segs values (side_one_constraint,2,'side_one_constraint'); /* side_two_constraint := rel_constraint__new( null, - ''rel_constraint'', - ''A: side 2 must be a blah of C'', + 'rel_constraint', + 'A: side 2 must be a blah of C', rel_segment__get_or_new(A, - ''blah_member_rel'', + 'blah_member_rel', null), - ''two'', + 'two', rel_segment__get_or_new(C, - ''blah_member_rel'', + 'blah_member_rel', null), null, null, @@ -281,22 +305,22 @@ side_one_constraint := rel_constraint__new( null, - ''rel_constraint'', - ''E: side 1 must be a component of B'', + 'rel_constraint', + 'E: side 1 must be a component of B', rel_segment__get_or_new(E, - ''composition_rel'', + 'composition_rel', null), - ''one'', + 'one', rel_segment__get_or_new(B, - ''composition_rel'', + 'composition_rel', null), null, null, null ); - insert into groups_test_segs values (side_two_constraint,3,''side_two_constraint 1''); - insert into groups_test_segs values (side_one_constraint,4,''side_one_constraint 1''); + insert into groups_test_segs values (side_two_constraint,3,'side_two_constraint 1'); + insert into groups_test_segs values (side_one_constraint,4,'side_one_constraint 1'); */ delete from acs_logs; @@ -308,43 +332,51 @@ -- joe is a blah of A, and F is component of E, so its legal to make joe -- a yippie of F. - rel_a := blah_member_rel__new(null, ''blah_member_rel'', A, joe); + rel_a := blah_member_rel__new(null, 'blah_member_rel', A, joe); - rel_b := yippie_member_rel__new(null, ''yippie_member_rel'', F, joe); + rel_b := yippie_member_rel__new(null, 'yippie_member_rel', F, joe); -- do constraints respect group hierarchy? If so, this will be legal: - rel_c := blah_member_rel__new(null, ''blah_member_rel'', B, jane); + rel_c := blah_member_rel__new(null, 'blah_member_rel', B, jane); - rel_d := yippie_member_rel__new(null, ''yippie_member_rel'', F, jane); + rel_d := yippie_member_rel__new(null, 'yippie_member_rel', F, jane); -- ILLEGAL MEMBERSHIPS: -- G is not a component of F, therefore no one can be a yippie of G -- This should violated 2 constraints (object one and object two are both -- invalid). - rel_e := yippie_member_rel__new(null, ''yippie_member_rel'', G, bob); + rel_e := yippie_member_rel__new(null, 'yippie_member_rel', G, bob); -- betty is not a blah of A, therefore she cannot be a yippie of F. - rel_f := yippie_member_rel__new(null, ''yippie_member_rel'', F, betty); + rel_f := yippie_member_rel__new(null, 'yippie_member_rel', F, betty); -- make sven be a regular member of A. Sven cannot be a yippie of F. rel_id := membership_rel__new(A, sven); - rel_g := yippie_member_rel__new(null, ''yippie_member_rel'', F, sven); + rel_g := yippie_member_rel__new(null, 'yippie_member_rel', F, sven); - insert into groups_test_segs values (rel_a,3,''a''); - insert into groups_test_segs values (rel_b,4,''b''); - insert into groups_test_segs values (rel_c,5,''c''); - insert into groups_test_segs values (rel_d,6,''d''); - insert into groups_test_segs values (rel_e,7,''e''); - insert into groups_test_segs values (rel_f,8,''f''); - insert into groups_test_segs values (rel_g,9,''g''); + insert into groups_test_segs values (rel_a,3,'a'); + insert into groups_test_segs values (rel_b,4,'b'); + insert into groups_test_segs values (rel_c,5,'c'); + insert into groups_test_segs values (rel_d,6,'d'); + insert into groups_test_segs values (rel_e,7,'e'); + insert into groups_test_segs values (rel_f,8,'f'); + insert into groups_test_segs values (rel_g,9,'g'); return null; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create function check_rel_constraints() returns integer as ' -declare + + +-- +-- procedure check_rel_constraints/0 +-- +CREATE OR REPLACE FUNCTION check_rel_constraints( + +) RETURNS integer AS $$ +DECLARE A integer; B integer; C integer; @@ -380,40 +412,40 @@ v_count integer; r record; -begin - select group_id into A from groups_test_groups where gname = ''A''; - select group_id into B from groups_test_groups where gname = ''B''; - select group_id into C from groups_test_groups where gname = ''C''; - select group_id into D from groups_test_groups where gname = ''D''; - select group_id into E from groups_test_groups where gname = ''E''; - select group_id into F from groups_test_groups where gname = ''F''; - select group_id into G from groups_test_groups where gname = ''G''; +BEGIN + select group_id into A from groups_test_groups where gname = 'A'; + select group_id into B from groups_test_groups where gname = 'B'; + select group_id into C from groups_test_groups where gname = 'C'; + select group_id into D from groups_test_groups where gname = 'D'; + select group_id into E from groups_test_groups where gname = 'E'; + select group_id into F from groups_test_groups where gname = 'F'; + select group_id into G from groups_test_groups where gname = 'G'; - select user_id into joe from groups_test_users where uname = ''joe''; - select user_id into jane from groups_test_users where uname = ''jane''; - select user_id into bob from groups_test_users where uname = ''bob''; - select user_id into betty from groups_test_users where uname = ''betty''; - select user_id into jack from groups_test_users where uname = ''jack''; - select user_id into jill from groups_test_users where uname = ''jill''; - select user_id into sven from groups_test_users where uname = ''sven''; - select user_id into stacy from groups_test_users where uname = ''stacy''; - select user_id into reg_users from groups_test_users where uname = ''reg_users''; + select user_id into joe from groups_test_users where uname = 'joe'; + select user_id into jane from groups_test_users where uname = 'jane'; + select user_id into bob from groups_test_users where uname = 'bob'; + select user_id into betty from groups_test_users where uname = 'betty'; + select user_id into jack from groups_test_users where uname = 'jack'; + select user_id into jill from groups_test_users where uname = 'jill'; + select user_id into sven from groups_test_users where uname = 'sven'; + select user_id into stacy from groups_test_users where uname = 'stacy'; + select user_id into reg_users from groups_test_users where uname = 'reg_users'; select seg_id into side_one_constraint from groups_test_segs - where sname = ''side_one_constraint''; + where sname = 'side_one_constraint'; select seg_id into side_two_constraint from groups_test_segs - where sname = ''side_two_constraint''; + where sname = 'side_two_constraint'; - select seg_id into rel_a from groups_test_segs where sname = ''a''; - select seg_id into rel_b from groups_test_segs where sname = ''b''; - select seg_id into rel_c from groups_test_segs where sname = ''c''; - select seg_id into rel_d from groups_test_segs where sname = ''d''; - select seg_id into rel_e from groups_test_segs where sname = ''e''; - select seg_id into rel_f from groups_test_segs where sname = ''f''; - select seg_id into rel_g from groups_test_segs where sname = ''g''; + select seg_id into rel_a from groups_test_segs where sname = 'a'; + select seg_id into rel_b from groups_test_segs where sname = 'b'; + select seg_id into rel_c from groups_test_segs where sname = 'c'; + select seg_id into rel_d from groups_test_segs where sname = 'd'; + select seg_id into rel_e from groups_test_segs where sname = 'e'; + select seg_id into rel_f from groups_test_segs where sname = 'f'; + select seg_id into rel_g from groups_test_segs where sname = 'g'; -- Make a couple of memberships. @@ -423,27 +455,27 @@ -- joe is a blah of A, and F is component of E, so its legal to make joe -- a yippie of F. - PERFORM rel_constraint_test_check(rel_a, ''f''); + PERFORM rel_constraint_test_check(rel_a, 'f'); - PERFORM rel_constraint_test_check(rel_b, ''f''); + PERFORM rel_constraint_test_check(rel_b, 'f'); -- do constraints respect group hierarchy? If so, this will be legal: - PERFORM rel_constraint_test_check(rel_c, ''f''); + PERFORM rel_constraint_test_check(rel_c, 'f'); - PERFORM rel_constraint_test_check(rel_d, ''f''); + PERFORM rel_constraint_test_check(rel_d, 'f'); -- ILLEGAL MEMBERSHIPS: -- G is not a component of F, therefore no one can be a yippie of G -- This should violated 2 constraints (object one and object two are both -- invalid). - PERFORM rel_constraint_test_check(rel_e, ''t''); + PERFORM rel_constraint_test_check(rel_e, 't'); -- betty is not a blah of A, therefore she cannot be a yippie of F. - PERFORM rel_constraint_test_check(rel_f, ''t''); + PERFORM rel_constraint_test_check(rel_f, 't'); -- make sven be a regular member of A. Sven cannot be a yippie of F. - PERFORM rel_constraint_test_check(rel_g, ''t''); + PERFORM rel_constraint_test_check(rel_g, 't'); -- TEST THE VIEWS (there should be 4 violated constraints, -- 1 side one violation and 3 side two violations. @@ -452,7 +484,7 @@ from rel_constraints_violated_one; if v_count != 1 then - raise NOTICE ''rel_constraints_violated_one should have 1 row. Found % rows.'', + raise NOTICE 'rel_constraints_violated_one should have 1 row. Found % rows.', v_count; PERFORM rel_constraint_dump_views(); end if; @@ -461,7 +493,7 @@ from rel_constraints_violated_two; if v_count != 3 then - raise NOTICE ''rel_constraints_violated_two should have 2 rows. Found % rows.'', + raise NOTICE 'rel_constraints_violated_two should have 2 rows. Found % rows.', v_count; PERFORM rel_constraint_dump_views(); end if; @@ -471,11 +503,11 @@ PERFORM rel_constraint__delete(side_two_constraint); select seg_id into side_one_constraint from groups_test_segs - where sname = ''side_one_constraint 1''; + where sname = 'side_one_constraint 1'; select seg_id into side_two_constraint from groups_test_segs - where sname = ''side_two_constraint 1''; + where sname = 'side_two_constraint 1'; PERFORM rel_constraint__delete(side_one_constraint); PERFORM rel_constraint__delete(side_two_constraint); @@ -489,9 +521,9 @@ end loop; -- Remove the test segments. - PERFORM rel_segment__delete(rel_segment__get(A,''blah_member_rel'')); - PERFORM rel_segment__delete(rel_segment__get(E,''composition_rel'')); - PERFORM rel_segment__delete(rel_segment__get(reg_users,''yippie_member_rel'')); + PERFORM rel_segment__delete(rel_segment__get(A,'blah_member_rel')); + PERFORM rel_segment__delete(rel_segment__get(E,'composition_rel')); + PERFORM rel_segment__delete(rel_segment__get(reg_users,'yippie_member_rel')); -- Remove the test groups. PERFORM acs_group__delete(G); @@ -514,7 +546,8 @@ return null; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select test_rel_constraints(); select check_rel_constraints(); Index: openacs-4/packages/acs-kernel/sql/postgresql/test/rel-segments-test-types-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/postgresql/test/rel-segments-test-types-create.sql,v diff -u -r1.2 -r1.3 --- openacs-4/packages/acs-kernel/sql/postgresql/test/rel-segments-test-types-create.sql 23 Mar 2001 00:21:50 -0000 1.2 +++ openacs-4/packages/acs-kernel/sql/postgresql/test/rel-segments-test-types-create.sql 7 Jul 2011 10:46:02 -0000 1.3 @@ -1,47 +1,47 @@ -create function inline_0 () -returns integer as ' -begin +CREATE OR REPLACE FUNCTION inline_0 () RETURNS integer AS $$ +BEGIN PERFORM acs_rel_type__create_type ( - ''blah_member_rel'', - ''Blah Membership Relationship'', - ''Blah Membership Relationships'', - ''membership_rel'', - ''blah_member_rels'', - ''rel_id'', - ''blah_member_rel'', - ''group'', + 'blah_member_rel', + 'Blah Membership Relationship', + 'Blah Membership Relationships', + 'membership_rel', + 'blah_member_rels', + 'rel_id', + 'blah_member_rel', + 'group', null, 0, null, - ''party'', - ''member'', + 'party', + 'member', 0, null ); PERFORM acs_rel_type__create_type ( - ''yippie_member_rel'', - ''Yippie Membership Relationship'', - ''Yippie Membership Relationships'', - ''membership_rel'', - ''yippie_member_rels'', - ''rel_id'', - ''yippie_member_rel'', - ''group'', + 'yippie_member_rel', + 'Yippie Membership Relationship', + 'Yippie Membership Relationships', + 'membership_rel', + 'yippie_member_rels', + 'rel_id', + 'yippie_member_rel', + 'group', null, 0, null, - ''party'', - ''member'', + 'party', + 'member', 0, null ); return null; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select inline_0 (); @@ -85,22 +85,30 @@ -- create or replace package body blah_member_rel -- function new -create function blah_member_rel__new (integer,varchar,integer,integer) -returns integer as ' -declare - new__rel_id alias for $1; - new__rel_type alias for $2; - new__object_id_one alias for $3; - new__object_id_two alias for $4; + + +-- added +select define_function_args('blah_member_rel__new','rel_id,rel_type,object_id_one,object_id_two'); + +-- +-- procedure blah_member_rel__new/4 +-- +CREATE OR REPLACE FUNCTION blah_member_rel__new( + new__rel_id integer, + new__rel_type varchar, + new__object_id_one integer, + new__object_id_two integer +) RETURNS integer AS $$ +DECLARE v_rel_id blah_member_rels.rel_id%TYPE; -begin +BEGIN v_rel_id := membership_rel__new( new__rel_id, new__rel_type, new__object_id_one, new__object_id_two, - ''approved'', + 'approved', null, null ); @@ -112,22 +120,32 @@ return v_rel_id; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure delete -create function blah_member_rel__delete (integer) -returns integer as ' -declare - delete__rel_id alias for $1; -begin + +-- added +select define_function_args('blah_member_rel__delete','rel_id'); + +-- +-- procedure blah_member_rel__delete/1 +-- +CREATE OR REPLACE FUNCTION blah_member_rel__delete( + delete__rel_id integer +) RETURNS integer AS $$ +DECLARE +BEGIN + delete from blah_member_rels where rel_id = delete__rel_id; PERFORM membership_rel__delete(delete__rel_id); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; @@ -155,22 +173,30 @@ -- create or replace package body yippie_member_rel -- function new -create function yippie_member_rel__new (integer,varchar,integer,integer) -returns integer as ' -declare - new__rel_id alias for $1; - new__rel_type alias for $2; - new__object_id_one alias for $3; - new__object_id_two alias for $4; + + +-- added +select define_function_args('yippie_member_rel__new','rel_id,rel_type,object_id_one,object_id_two'); + +-- +-- procedure yippie_member_rel__new/4 +-- +CREATE OR REPLACE FUNCTION yippie_member_rel__new( + new__rel_id integer, + new__rel_type varchar, + new__object_id_one integer, + new__object_id_two integer +) RETURNS integer AS $$ +DECLARE v_rel_id yippie_member_rels.rel_id%TYPE; -begin +BEGIN v_rel_id := membership_rel__new( new__rel_id, new__rel_type, new__object_id_one, new__object_id_two, - ''approved'', + 'approved', null, null ); @@ -182,22 +208,32 @@ return v_rel_id; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure delete -create function yippie_member_rel__delete (integer) -returns integer as ' -declare - delete__rel_id alias for $1; -begin + +-- added +select define_function_args('yippie_member_rel__delete','rel_id'); + +-- +-- procedure yippie_member_rel__delete/1 +-- +CREATE OR REPLACE FUNCTION yippie_member_rel__delete( + delete__rel_id integer +) RETURNS integer AS $$ +DECLARE +BEGIN + delete from yippie_member_rels where rel_id = delete__rel_id; PERFORM membership_rel__delete(delete__rel_id); return 0; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; Index: openacs-4/packages/acs-kernel/sql/postgresql/test/rel-segments-test.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/postgresql/test/rel-segments-test.sql,v diff -u -r1.3 -r1.4 --- openacs-4/packages/acs-kernel/sql/postgresql/test/rel-segments-test.sql 24 Mar 2001 00:34:53 -0000 1.3 +++ openacs-4/packages/acs-kernel/sql/postgresql/test/rel-segments-test.sql 7 Jul 2011 10:46:02 -0000 1.4 @@ -31,15 +31,23 @@ \i rel-segments-test-types-create.sql -create function rel_segment_test_check (integer, integer, integer) -returns boolean as ' -declare - test_check__segment_id alias for $1; - test_check__party_id alias for $2; - test_check__container_id alias for $3; + + +-- added +select define_function_args('rel_segment_test_check','segment_id,party_id,container_id'); + +-- +-- procedure rel_segment_test_check/3 +-- +CREATE OR REPLACE FUNCTION rel_segment_test_check( + test_check__segment_id integer, + test_check__party_id integer, + test_check__container_id integer +) RETURNS boolean AS $$ +DECLARE v_pass_p boolean; str text; -begin +BEGIN select count(*) > 0 into v_pass_p from rel_segment_party_map @@ -49,30 +57,38 @@ if NOT v_pass_p then - str := ''Row missing from rel_segment_party_map for'' || - '' segment '' || + str := 'Row missing from rel_segment_party_map for' || + ' segment ' || acs_object__name(test_check__segment_id) || - '' ('' || test_check__segment_id || '')'' || - '', party '' || + ' (' || test_check__segment_id || ')' || + ', party ' || acs_object__name(test_check__party_id) || - '' ('' || test_check__party_id || '')'' || - '', container '' || + ' (' || test_check__party_id || ')' || + ', container ' || acs_object__name(test_check__container_id) || - '' ('' || test_check__container_id || '')''; + ' (' || test_check__container_id || ')'; - raise NOTICE ''%'', str; + raise NOTICE '%', str; - PERFORM acs_log__error(''rel_segment_test_check'', str); + PERFORM acs_log__error('rel_segment_test_check', str); end if; return v_pass_p; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create function test_segs() returns integer as ' -declare + + +-- +-- procedure test_segs/0 +-- +CREATE OR REPLACE FUNCTION test_segs( + +) RETURNS integer AS $$ +DECLARE A integer; B integer; C integer; @@ -95,51 +111,51 @@ seg_F integer; rel_id integer; -begin +BEGIN -- Create the test groups. - A := acs_group__new(''A''); - B := acs_group__new(''B''); - C := acs_group__new(''C''); - D := acs_group__new(''D''); - E := acs_group__new(''E''); - F := acs_group__new(''F''); - G := acs_group__new(''G''); + A := acs_group__new('A'); + B := acs_group__new('B'); + C := acs_group__new('C'); + D := acs_group__new('D'); + E := acs_group__new('E'); + F := acs_group__new('F'); + G := acs_group__new('G'); - insert into groups_test_groups values (A,1,''A''); - insert into groups_test_groups values (B,2,''B''); - insert into groups_test_groups values (C,3,''C''); - insert into groups_test_groups values (D,4,''D''); - insert into groups_test_groups values (E,5,''E''); - insert into groups_test_groups values (F,6,''F''); - insert into groups_test_groups values (G,7,''G''); + insert into groups_test_groups values (A,1,'A'); + insert into groups_test_groups values (B,2,'B'); + insert into groups_test_groups values (C,3,'C'); + insert into groups_test_groups values (D,4,'D'); + insert into groups_test_groups values (E,5,'E'); + insert into groups_test_groups values (F,6,'F'); + insert into groups_test_groups values (G,7,'G'); -- Create the test members. - joe := acs_user__new(''joe@asdf.com'',''Joe'', - ''Smith'',''assword'',''p''); - jane := acs_user__new(''jane@asdf.com'',''Jane'', - ''Smith'',''assword'',''p''); - bob := acs_user__new(''bob@asdf.com'',''Bob'', - ''Smith'',''assword'',''p''); - betty := acs_user__new(''betty@asdf.com'',''Betty'', - ''Smith'',''assword'',''p''); - jack := acs_user__new(''jack@asdf.com'',''Jack'', - ''Smith'',''assword'',''p''); - jill := acs_user__new(''jill@asdf.com'',''Jill'', - ''Smith'',''assword'',''p''); - sven := acs_user__new(''sven@asdf.com'',''Sven'', - ''Smith'',''assword'',''p''); - stacy := acs_user__new(''stacy@asdf.com'',''Stacy'', - ''Smith'',''assword'',''p''); + joe := acs_user__new('joe@asdf.com','Joe', + 'Smith','assword','p'); + jane := acs_user__new('jane@asdf.com','Jane', + 'Smith','assword','p'); + bob := acs_user__new('bob@asdf.com','Bob', + 'Smith','assword','p'); + betty := acs_user__new('betty@asdf.com','Betty', + 'Smith','assword','p'); + jack := acs_user__new('jack@asdf.com','Jack', + 'Smith','assword','p'); + jill := acs_user__new('jill@asdf.com','Jill', + 'Smith','assword','p'); + sven := acs_user__new('sven@asdf.com','Sven', + 'Smith','assword','p'); + stacy := acs_user__new('stacy@asdf.com','Stacy', + 'Smith','assword','p'); - insert into groups_test_users values (joe,1,''joe''); - insert into groups_test_users values (jane,2,''jane''); - insert into groups_test_users values (bob,3,''bob''); - insert into groups_test_users values (betty,4,''betty''); - insert into groups_test_users values (jack,5,''jack''); - insert into groups_test_users values (jill,6,''jill''); - insert into groups_test_users values (sven,7,''sven''); - insert into groups_test_users values (stacy,8,''stacy''); + insert into groups_test_users values (joe,1,'joe'); + insert into groups_test_users values (jane,2,'jane'); + insert into groups_test_users values (bob,3,'bob'); + insert into groups_test_users values (betty,4,'betty'); + insert into groups_test_users values (jack,5,'jack'); + insert into groups_test_users values (jill,6,'jill'); + insert into groups_test_users values (sven,7,'sven'); + insert into groups_test_users values (stacy,8,'stacy'); -- Make a couple of compositions. @@ -153,57 +169,65 @@ -- Make a couple of memberships. - rel_id := blah_member_rel__new(null, ''blah_member_rel'', B, joe); - rel_id := yippie_member_rel__new(null, ''yippie_member_rel'', B, jane); - rel_id := blah_member_rel__new(null, ''blah_member_rel'', B, betty); - rel_id := yippie_member_rel__new(null, ''yippie_member_rel'', A, bob); - rel_id := blah_member_rel__new(null, ''blah_member_rel'', A, betty); - rel_id := yippie_member_rel__new(null, ''yippie_member_rel'', E, betty); + rel_id := blah_member_rel__new(null, 'blah_member_rel', B, joe); + rel_id := yippie_member_rel__new(null, 'yippie_member_rel', B, jane); + rel_id := blah_member_rel__new(null, 'blah_member_rel', B, betty); + rel_id := yippie_member_rel__new(null, 'yippie_member_rel', A, bob); + rel_id := blah_member_rel__new(null, 'blah_member_rel', A, betty); + rel_id := yippie_member_rel__new(null, 'yippie_member_rel', E, betty); -- define a few segments. -- the segment of all parties that are blah members of G seg_G_blahs := rel_segment__new(null, - ''rel_segment'', + 'rel_segment', now(), null, null, null, null, - ''Blahs of Group G'', + 'Blahs of Group G', G, - ''blah_member_rel'', + 'blah_member_rel', null ); -- the segment of all parties that are yippie members of E seg_E_yippies := rel_segment__new(null, - ''rel_segment'', + 'rel_segment', now(), null, null, null, null, - ''Yippies of Group E'', + 'Yippies of Group E', E, - ''yippie_member_rel'', + 'yippie_member_rel', null ); - seg_F := rel_segment__get_or_new(F,''membership_rel'',null); + seg_F := rel_segment__get_or_new(F,'membership_rel',null); - insert into groups_test_segs values (seg_G_blahs,1,''seg_G_blahs''); - insert into groups_test_segs values (seg_E_yippies,2,''seg_E_yippies''); - insert into groups_test_segs values (seg_F,3,''seg_F''); + insert into groups_test_segs values (seg_G_blahs,1,'seg_G_blahs'); + insert into groups_test_segs values (seg_E_yippies,2,'seg_E_yippies'); + insert into groups_test_segs values (seg_F,3,'seg_F'); delete from acs_logs; return null; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create function check_segs() returns integer as ' -declare + + +-- +-- procedure check_segs/0 +-- +CREATE OR REPLACE FUNCTION check_segs( + +) RETURNS integer AS $$ +DECLARE A integer; B integer; C integer; @@ -228,36 +252,36 @@ rel_id integer; r record; str varchar; -begin +BEGIN - select group_id into A from groups_test_groups where gname = ''A''; - select group_id into B from groups_test_groups where gname = ''B''; - select group_id into C from groups_test_groups where gname = ''C''; - select group_id into D from groups_test_groups where gname = ''D''; - select group_id into E from groups_test_groups where gname = ''E''; - select group_id into F from groups_test_groups where gname = ''F''; - select group_id into G from groups_test_groups where gname = ''G''; + select group_id into A from groups_test_groups where gname = 'A'; + select group_id into B from groups_test_groups where gname = 'B'; + select group_id into C from groups_test_groups where gname = 'C'; + select group_id into D from groups_test_groups where gname = 'D'; + select group_id into E from groups_test_groups where gname = 'E'; + select group_id into F from groups_test_groups where gname = 'F'; + select group_id into G from groups_test_groups where gname = 'G'; - select user_id into joe from groups_test_users where uname = ''joe''; - select user_id into jane from groups_test_users where uname = ''jane''; - select user_id into bob from groups_test_users where uname = ''bob''; - select user_id into betty from groups_test_users where uname = ''betty''; - select user_id into jack from groups_test_users where uname = ''jack''; - select user_id into jill from groups_test_users where uname = ''jill''; - select user_id into sven from groups_test_users where uname = ''sven''; - select user_id into stacy from groups_test_users where uname = ''stacy''; + select user_id into joe from groups_test_users where uname = 'joe'; + select user_id into jane from groups_test_users where uname = 'jane'; + select user_id into bob from groups_test_users where uname = 'bob'; + select user_id into betty from groups_test_users where uname = 'betty'; + select user_id into jack from groups_test_users where uname = 'jack'; + select user_id into jill from groups_test_users where uname = 'jill'; + select user_id into sven from groups_test_users where uname = 'sven'; + select user_id into stacy from groups_test_users where uname = 'stacy'; select seg_id into seg_G_blahs from groups_test_segs - where sname = ''seg_G_blahs''; + where sname = 'seg_G_blahs'; select seg_id into seg_E_yippies from groups_test_segs - where sname = ''seg_E_yippies''; + where sname = 'seg_E_yippies'; select seg_id into seg_F from groups_test_segs - where sname = ''seg_F''; + where sname = 'seg_F'; -- group_element_index_dump; -- rel_segment_party_map_dump; @@ -268,78 +292,78 @@ -- 2. seg_E_yippies should include bob, and jane, betty -- check: seg_G_blahs contains joe with container B - if rel_segment_test_check(seg_G_blahs, joe, B) = ''f'' then - str := ''Segment '' || acs_object__name(seg_G_blahs) || - ''('' || seg_G_blahs || '') failed. Group_id = '' + if rel_segment_test_check(seg_G_blahs, joe, B) = 'f' then + str := 'Segment ' || acs_object__name(seg_G_blahs) || + '(' || seg_G_blahs || ') failed. Group_id = ' || G; - raise NOTICE ''%'', str; + raise NOTICE '%', str; end if; -- check: seg_G_blahs contains betty with container B - if rel_segment_test_check(seg_G_blahs, betty, B) = ''f'' then - str := ''Segment '' || acs_object__name(seg_G_blahs) || - ''('' || seg_G_blahs || '') failed. Group_id = '' + if rel_segment_test_check(seg_G_blahs, betty, B) = 'f' then + str := 'Segment ' || acs_object__name(seg_G_blahs) || + '(' || seg_G_blahs || ') failed. Group_id = ' || G; - raise NOTICE ''%'', str; + raise NOTICE '%', str; end if; -- check: seg_G_blahs contains betty with container A - if rel_segment_test_check(seg_G_blahs, betty, A) = ''f'' then - str := ''Segment '' || acs_object__name(seg_G_blahs) || - ''('' || seg_G_blahs || '') failed. Group_id = '' + if rel_segment_test_check(seg_G_blahs, betty, A) = 'f' then + str := 'Segment ' || acs_object__name(seg_G_blahs) || + '(' || seg_G_blahs || ') failed. Group_id = ' || G; - raise NOTICE ''%'', str; + raise NOTICE '%', str; end if; -- check: seg_E_yippies contains jane with container B - if rel_segment_test_check(seg_E_yippies, jane, B) = ''f'' then - str := ''Segment '' || acs_object__name(seg_E_yippies) || - ''('' || seg_E_yippies || '') failed. Group_id = '' + if rel_segment_test_check(seg_E_yippies, jane, B) = 'f' then + str := 'Segment ' || acs_object__name(seg_E_yippies) || + '(' || seg_E_yippies || ') failed. Group_id = ' || E; - raise NOTICE ''%'', str; + raise NOTICE '%', str; end if; -- check: seg_E_yippies contains bob with container A - if rel_segment_test_check(seg_E_yippies, bob, A) = ''f'' then - str := ''Segment '' || acs_object__name(seg_E_yippies) || - ''('' || seg_E_yippies || '') failed. Group_id = '' + if rel_segment_test_check(seg_E_yippies, bob, A) = 'f' then + str := 'Segment ' || acs_object__name(seg_E_yippies) || + '(' || seg_E_yippies || ') failed. Group_id = ' || E; - raise NOTICE ''%'', str; + raise NOTICE '%', str; end if; -- check: seg_E_yippies contains betty with container E - if rel_segment_test_check(seg_E_yippies, betty, E) = ''f'' then - str := ''Segment '' || acs_object__name(seg_E_yippies) || - ''('' || seg_E_yippies || '') failed. Group_id = '' + if rel_segment_test_check(seg_E_yippies, betty, E) = 'f' then + str := 'Segment ' || acs_object__name(seg_E_yippies) || + '(' || seg_E_yippies || ') failed. Group_id = ' || E; - raise NOTICE ''%'', str; + raise NOTICE '%', str; end if; -- Now we test on-the-fly creation of rel-segments with the get_or_new -- function: -- The segment of all memers of F should contain jane through group B - if rel_segment_test_check(seg_F, jane, B) = ''f'' then - str := ''Segment '' || - acs_object__name(rel_segment__get(F,''membership_rel'')) || - ''('' || rel_segment__get(F,''membership_rel'') - || '') failed. Group_id = '' || F; - raise NOTICE ''%'', str; + if rel_segment_test_check(seg_F, jane, B) = 'f' then + str := 'Segment ' || + acs_object__name(rel_segment__get(F,'membership_rel')) || + '(' || rel_segment__get(F,'membership_rel') + || ') failed. Group_id = ' || F; + raise NOTICE '%', str; end if; -- The segment of all memers of F should contain betty through group A - if rel_segment_test_check(seg_F, betty, A) = ''f'' then - str := ''Segment '' || - acs_object__name(rel_segment__get(F,''membership_rel'')) || - ''('' || rel_segment__get(F,''membership_rel'') - || '') failed. Group_id = '' || A; - raise NOTICE ''%'', str; + if rel_segment_test_check(seg_F, betty, A) = 'f' then + str := 'Segment ' || + acs_object__name(rel_segment__get(F,'membership_rel')) || + '(' || rel_segment__get(F,'membership_rel') + || ') failed. Group_id = ' || A; + raise NOTICE '%', str; end if; -- Remove the test segments. PERFORM rel_segment__delete(seg_G_blahs); PERFORM rel_segment__delete(seg_E_yippies); - PERFORM rel_segment__delete(rel_segment__get(F,''membership_rel'')); + PERFORM rel_segment__delete(rel_segment__get(F,'membership_rel')); -- Remove the test memebership relations for r in select * from blah_member_rels LOOP @@ -371,7 +395,8 @@ return null; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select test_segs(); select check_segs(); Index: openacs-4/packages/acs-kernel/sql/postgresql/test-harness/acs-core.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/postgresql/test-harness/acs-core.sql,v diff -u -r1.2 -r1.3 --- openacs-4/packages/acs-kernel/sql/postgresql/test-harness/acs-core.sql 23 Mar 2001 00:21:50 -0000 1.2 +++ openacs-4/packages/acs-kernel/sql/postgresql/test-harness/acs-core.sql 7 Jul 2011 10:46:02 -0000 1.3 @@ -10,53 +10,69 @@ -- @cvs-id $Id$ -- -create function test_acs_core () returns integer as ' -declare + + +-- +-- procedure test_acs_core/0 +-- +CREATE OR REPLACE FUNCTION test_acs_core( + +) RETURNS integer AS $$ +DECLARE uid users.user_id%TYPE; tname varchar; -begin - raise notice ''Calling acs_user.new() to create user 1''; +BEGIN + raise notice 'Calling acs_user.new() to create user 1'; uid := acs_user__new(1, - ''user'', + 'user', now(), null, - ''127.0.0.1'', - ''jane.doe@arsdigita.com'', + '127.0.0.1', + 'jane.doe@arsdigita.com', null, - ''Jane'', - ''Doe'', - ''janedoerules'', + 'Jane', + 'Doe', + 'janedoerules', null, null, null, null, - ''t'', + 't', null ); tname := acs_object__name(1); - raise NOTICE ''Calling acs_object.name to get the name of user: %'', tname; + raise NOTICE 'Calling acs_object.name to get the name of user: %', tname; - raise NOTICE ''Calling acs_user.delete to delete user 1''; + raise NOTICE 'Calling acs_user.delete to delete user 1'; -- PERFORM acs_user__delete(1); return NULL; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create function test_del_user () returns integer as ' -declare -begin + + +-- +-- procedure test_del_user/0 +-- +CREATE OR REPLACE FUNCTION test_del_user( + +) RETURNS integer AS $$ +DECLARE +BEGIN perform acs_user__delete(1); return null; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select test_acs_core (); Index: openacs-4/packages/acs-subsite/tcl/plpgsql-utility-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-subsite/tcl/plpgsql-utility-procs.tcl,v diff -u -r1.4 -r1.5 --- openacs-4/packages/acs-subsite/tcl/plpgsql-utility-procs.tcl 10 Jan 2007 21:22:06 -0000 1.4 +++ openacs-4/packages/acs-subsite/tcl/plpgsql-utility-procs.tcl 7 Jul 2011 10:46:02 -0000 1.5 @@ -63,7 +63,7 @@ if { [info exists user_supplied($arg_name)] } { lappend pieces "${prepend}$user_supplied($arg_name)" } else { - if { $arg_default eq "" } { + if { $arg_default eq "" || $arg_default eq "null"} { lappend pieces "NULL" } else { lappend pieces "'[db_quote $arg_default]'"