Index: openacs-4/packages/notes/notes.info =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/notes/notes.info,v diff -u -N -r1.7 -r1.8 --- openacs-4/packages/notes/notes.info 11 Dec 2003 21:40:08 -0000 1.7 +++ openacs-4/packages/notes/notes.info 10 Feb 2004 19:47:34 -0000 1.8 @@ -7,7 +7,7 @@ f t - + oracle postgresql @@ -20,38 +20,10 @@ This is a sample application for OpenACS 4.x to show how applications should be built, unfortunately it has not kept pace with current best practices. - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Index: openacs-4/packages/notes/sql/oracle/notes-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/notes/sql/oracle/notes-create.sql,v diff -u -N -r1.4 -r1.5 --- openacs-4/packages/notes/sql/oracle/notes-create.sql 30 Sep 2003 12:10:08 -0000 1.4 +++ openacs-4/packages/notes/sql/oracle/notes-create.sql 10 Feb 2004 19:47:35 -0000 1.5 @@ -12,9 +12,9 @@ object_type => 'note', pretty_name => 'Note', pretty_plural => 'Notes', - table_name => 'NOTES', - id_column => 'NOTE_ID', - name_method => 'NOTE.NAME' + table_name => 'notes', + id_column => 'note_id', + name_method => 'note.name' ); end; / @@ -25,15 +25,15 @@ begin attr_id := acs_attribute.create_attribute ( object_type => 'note', - attribute_name => 'TITLE', + attribute_name => 'title', pretty_name => 'Title', pretty_plural => 'Titles', datatype => 'string' ); attr_id := acs_attribute.create_attribute ( object_type => 'note', - attribute_name => 'BODY', + attribute_name => 'body', pretty_name => 'Body', pretty_plural => 'Bodies', datatype => 'string' @@ -44,16 +44,14 @@ create table notes ( note_id integer references acs_objects(object_id) primary key, - owner_id integer references users(user_id), title varchar(255) not null, - body varchar(1024) + body varchar(4000) ); create or replace package note as function new ( note_id in notes.note_id%TYPE default null, - owner_id in notes.owner_id%TYPE default null, title in notes.title%TYPE, body in notes.body%TYPE, object_type in acs_object_types.object_type%TYPE @@ -81,7 +79,6 @@ as function new ( note_id in notes.note_id%TYPE default null, - owner_id in notes.owner_id%TYPE default null, title in notes.title%TYPE, body in notes.body%TYPE, object_type in acs_object_types.object_type%TYPE @@ -106,13 +103,13 @@ ); insert into notes - (note_id, owner_id, title, body) + (note_id, title, body) values - (v_note_id, owner_id, title, body); + (v_note_id, title, body); acs_permission.grant_permission( object_id => v_note_id, - grantee_id => owner_id, + grantee_id => creation_user, privilege => 'admin' ); Index: openacs-4/packages/notes/sql/oracle/upgrade/upgrade-0.12d-0.13d.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/notes/sql/oracle/upgrade/upgrade-0.12d-0.13d.sql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/notes/sql/oracle/upgrade/upgrade-0.12d-0.13d.sql 10 Feb 2004 19:47:35 -0000 1.1 @@ -0,0 +1,99 @@ +create or replace package note +as + function new ( + note_id in notes.note_id%TYPE default null, + title in notes.title%TYPE, + body in notes.body%TYPE, + object_type in acs_object_types.object_type%TYPE + default 'note', + creation_date in acs_objects.creation_date%TYPE + default sysdate, + creation_user in acs_objects.creation_user%TYPE + default null, + creation_ip in acs_objects.creation_ip%TYPE default null, + context_id in acs_objects.context_id%TYPE default null + ) return notes.note_id%TYPE; + + procedure del ( + note_id in notes.note_id%TYPE + ); + + function name ( + note_id in notes.note_id%TYPE + ) return notes.title%TYPE; +end note; +/ +show errors + +create or replace package body note +as + function new ( + note_id in notes.note_id%TYPE default null, + title in notes.title%TYPE, + body in notes.body%TYPE, + object_type in acs_object_types.object_type%TYPE + default 'note', + creation_date in acs_objects.creation_date%TYPE + default sysdate, + creation_user in acs_objects.creation_user%TYPE + default null, + creation_ip in acs_objects.creation_ip%TYPE default null, + context_id in acs_objects.context_id%TYPE default null + ) return notes.note_id%TYPE + is + v_note_id integer; + begin + v_note_id := acs_object.new ( + object_id => note_id, + object_type => object_type, + creation_date => creation_date, + creation_user => creation_user, + creation_ip => creation_ip, + context_id => context_id + ); + + insert into notes + (note_id, title, body) + values + (v_note_id, title, body); + + acs_permission.grant_permission( + object_id => v_note_id, + grantee_id => creation_user, + privilege => 'admin' + ); + + return v_note_id; + end new; + + procedure del ( + note_id in notes.note_id%TYPE + ) + is + begin + delete from acs_permissions + where object_id = note.del.note_id; + + delete from notes + where note_id = note.del.note_id; + + acs_object.del(note_id); + end del; + + function name ( + note_id in notes.note_id%TYPE + ) return notes.title%TYPE + is + v_note_name notes.title%TYPE; + begin + select title into v_note_name + from notes + where note_id = name.note_id; + + return v_note_name; + end name; +end note; +/ +show errors; + +alter table notes drop column owner_id; Index: openacs-4/packages/notes/sql/postgresql/notes-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/notes/sql/postgresql/notes-create.sql,v diff -u -N -r1.5 -r1.6 --- openacs-4/packages/notes/sql/postgresql/notes-create.sql 17 May 2003 10:51:28 -0000 1.5 +++ openacs-4/packages/notes/sql/postgresql/notes-create.sql 10 Feb 2004 19:47:36 -0000 1.6 @@ -12,17 +12,17 @@ returns integer as ' begin PERFORM acs_object_type__create_type ( - ''note'', -- object_type - ''Note'', -- pretty_name - ''Notes'', -- pretty_plural - ''acs_object'', -- supertype - ''notes'', -- table_name - ''note_id'', -- id_column - null, -- package_name - ''f'', -- abstract_p - null, -- type_extension_table - ''note.name'' -- name_method - ); + ''note'', -- object_type + ''Note'', -- pretty_name + ''Notes'', -- pretty_plural + ''acs_object'', -- supertype + ''notes'', -- table_name + ''note_id'', -- id_column + null, -- package_name + ''f'', -- abstract_p + null, -- type_extension_table + ''note.name'' -- name_method + ); return 0; end;' language 'plpgsql'; @@ -35,36 +35,36 @@ returns integer as ' begin PERFORM acs_attribute__create_attribute ( - ''note'', -- object_type - ''TITLE'', -- attribute_name - ''string'', -- datatype - ''Title'', -- pretty_name - ''Titles'', -- pretty_plural - null, -- table_name - null, -- column_name - null, -- default_value - 1, -- min_n_values - 1, -- max_n_values - null, -- sort_order - ''type_specific'', -- storage - ''f'' -- static_p - ); + ''note'', -- object_type + ''title'', -- attribute_name + ''string'', -- datatype + ''Title'', -- pretty_name + ''Titles'', -- pretty_plural + null, -- table_name + null, -- column_name + null, -- default_value + 1, -- min_n_values + 1, -- max_n_values + null, -- sort_order + ''type_specific'', -- storage + ''f'' -- static_p + ); PERFORM acs_attribute__create_attribute ( - ''note'', -- object_type - ''BODY'', -- attribute_name - ''string'', -- datatype - ''Body'', -- pretty_name - ''Bodies'', -- pretty_plural - null, -- table_name - null, -- column_name - null, -- default_value - 1, -- min_n_values - 1, -- max_n_values - null, -- sort_order - ''type_specific'', -- storage - ''f'' -- static_p - ); + ''note'', -- object_type + ''body'', -- attribute_name + ''string'', -- datatype + ''Body'', -- pretty_name + ''Bodies'', -- pretty_plural + null, -- table_name + null, -- column_name + null, -- default_value + 1, -- min_n_values + 1, -- max_n_values + null, -- sort_order + ''type_specific'', -- storage + ''f'' -- static_p + ); return 0; end;' language 'plpgsql'; @@ -75,72 +75,72 @@ create table notes ( note_id integer - constraint notes_note_id_fk - references acs_objects(object_id) - constraint notes_note_id_pk - primary key, - owner_id integer - constraint notes_owner_id_fk - references users(user_id), + constraint notes_note_id_fk + references acs_objects(object_id) + constraint notes_note_id_pk + primary key, title varchar(255) - constraint notes_title_nn - not null, - body varchar(1024) + constraint notes_title_nn + not null, + body text ); -create function note__new (integer,integer,varchar,varchar,varchar,timestamptz,integer,varchar,integer) +select define_function_args('note__new','note_id,title,body,object_type;note,creation_date;now,creation_user,creation_ip,context_id'); + +create function note__new (integer,varchar,varchar,varchar,timestamptz,integer,varchar,integer) returns integer as ' declare - p_note_id alias for $1; -- default null - p_owner_id alias for $2; -- default null - p_title alias for $3; - p_body alias for $4; - p_object_type alias for $5; -- default ''note'' - p_creation_date alias for $6; -- default now() - p_creation_user alias for $7; -- default null - p_creation_ip alias for $8; -- default null - p_context_id alias for $9; -- default null - v_note_id notes.note_id%TYPE; + p_note_id alias for $1; -- default null + p_title alias for $2; + p_body alias for $3; + p_object_type alias for $4; -- default ''note'' + p_creation_date alias for $5; -- default now() + p_creation_user alias for $6; -- default null + p_creation_ip alias for $7; -- default null + p_context_id alias for $8; -- default null + v_note_id notes.note_id%TYPE; begin - v_note_id := acs_object__new ( - p_note_id, - p_object_type, - p_creation_date, - p_creation_user, - p_creation_ip, - p_context_id - ); + v_note_id := acs_object__new ( + p_note_id, + p_object_type, + p_creation_date, + p_creation_user, + p_creation_ip, + p_context_id + ); - insert into notes - (note_id, owner_id, title, body) - values - (v_note_id, p_owner_id, p_title, p_body); + insert into notes + (note_id, title, body) + values + (v_note_id, p_title, p_body); - PERFORM acs_permission__grant_permission( + PERFORM acs_permission__grant_permission( v_note_id, - p_owner_id, + p_creation_user, ''admin'' ); - return v_note_id; + return v_note_id; end;' language 'plpgsql'; -create function note__delete (integer) +select define_function_args('note__del','note_id'); + +create function note__del (integer) returns integer as ' declare - p_note_id alias for $1; + p_note_id alias for $1; begin delete from acs_permissions - where object_id = p_note_id; + where object_id = p_note_id; - delete from notes - where note_id = p_note_id; + delete from notes + where note_id = p_note_id; - raise NOTICE ''Deleting note...''; - PERFORM acs_object__delete(p_note_id); + raise NOTICE ''Deleting note...''; + PERFORM acs_object__delete(p_note_id); - return 0; + return 0; end;' language 'plpgsql'; @@ -150,9 +150,9 @@ p_note_id alias for $1; v_note_name notes.title%TYPE; begin - select title into v_note_name - from notes - where note_id = p_note_id; + select title into v_note_name + from notes + where note_id = p_note_id; return v_note_name; end; Index: openacs-4/packages/notes/sql/postgresql/notes-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/notes/sql/postgresql/notes-drop.sql,v diff -u -N -r1.6 -r1.7 --- openacs-4/packages/notes/sql/postgresql/notes-drop.sql 17 May 2003 10:51:28 -0000 1.6 +++ openacs-4/packages/notes/sql/postgresql/notes-drop.sql 10 Feb 2004 19:47:36 -0000 1.7 @@ -7,8 +7,8 @@ \i notes-sc-drop.sql --drop functions -drop function note__new (integer,integer,varchar,varchar,varchar,timestamptz,integer,varchar,integer); -drop function note__delete (integer); +drop function note__new (integer,varchar,varchar,varchar,timestamptz,integer,varchar,integer); +drop function note__del(integer); drop function note__name (integer); --drop permissions Index: openacs-4/packages/notes/sql/postgresql/notes-sc-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/notes/sql/postgresql/notes-sc-create.sql,v diff -u -N -r1.3 -r1.4 --- openacs-4/packages/notes/sql/postgresql/notes-sc-create.sql 30 Dec 2002 12:06:11 -0000 1.3 +++ openacs-4/packages/notes/sql/postgresql/notes-sc-create.sql 10 Feb 2004 19:47:36 -0000 1.4 @@ -33,21 +33,21 @@ create function notes__itrg () -returns opaque as ' +returns trigger as ' begin perform search_observer__enqueue(new.note_id,''INSERT''); return new; end;' language 'plpgsql'; create function notes__dtrg () -returns opaque as ' +returns trigger as ' begin perform search_observer__enqueue(old.note_id,''DELETE''); return old; end;' language 'plpgsql'; create function notes__utrg () -returns opaque as ' +returns trigger as ' begin perform search_observer__enqueue(old.note_id,''UPDATE''); return old; @@ -62,8 +62,3 @@ create trigger notes__utrg after update on notes for each row execute procedure notes__utrg (); - - - - - Index: openacs-4/packages/notes/sql/postgresql/upgrade/upgrade-0.12d-0.13d.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/notes/sql/postgresql/upgrade/upgrade-0.12d-0.13d.sql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/notes/sql/postgresql/upgrade/upgrade-0.12d-0.13d.sql 10 Feb 2004 19:47:36 -0000 1.1 @@ -0,0 +1,40 @@ +select define_function_args('note__new','note_id,title,body,object_type;note,creation_date;now,creation_user,creation_ip,context_id'); + +create or replace function note__new (integer,varchar,varchar,varchar,timestamptz,integer,varchar,integer) +returns integer as ' +declare + p_note_id alias for $1; -- default null + p_title alias for $2; + p_body alias for $3; + p_object_type alias for $4; -- default ''note'' + p_creation_date alias for $5; -- default now() + p_creation_user alias for $6; -- default null + p_creation_ip alias for $7; -- default null + p_context_id alias for $8; -- default null + v_note_id notes.note_id%TYPE; +begin + v_note_id := acs_object__new ( + p_note_id, + p_object_type, + p_creation_date, + p_creation_user, + p_creation_ip, + p_context_id + ); + + insert into notes + (note_id, title, body) + values + (v_note_id, p_title, p_body); + + PERFORM acs_permission__grant_permission( + v_note_id, + p_creation_user, + ''admin'' + ); + + return v_note_id; + +end;' language 'plpgsql'; + +alter table notes drop column owner_id;