Index: openacs-4/packages/acs-kernel/sql/test/rel-constraints-test.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/test/rel-constraints-test.sql,v diff -u -r1.3 -r1.4 --- openacs-4/packages/acs-kernel/sql/test/rel-constraints-test.sql 30 Apr 2001 01:34:02 -0000 1.3 +++ openacs-4/packages/acs-kernel/sql/test/rel-constraints-test.sql 30 Mar 2013 19:32:40 -0000 1.4 @@ -19,12 +19,12 @@ uname varchar(100) ); -create function rel_constraint_dump_views() returns integer as ' +CREATE OR REPLACE FUNCTION rel_constraint_dump_views() RETURNS integer AS $$ r record; str varchar; -begin +BEGIN - raise NOTICE ''Contents of view ''rel_constraints_violated_one'':''; + raise NOTICE 'Contents of view 'rel_constraints_violated_one':'; for r in select * from rel_constraints_violated_one LOOP @@ -33,11 +33,11 @@ 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 @@ -46,32 +46,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, boolean) -returns integer as ' -declare - rel_id alias for $1; - expect_violation_p alias for $2; + + +-- added +select define_function_args('rel_constraint_test_check','rel_id,expect_violation_p'); + +-- +-- procedure rel_constraint_test_check/2 +-- +CREATE OR REPLACE FUNCTION rel_constraint_test_check( + rel_id integer, + expect_violation_p boolean +) RETURNS integer AS $$ +DECLARE v_violation_msg varchar(4000); v_violation_p boolean; 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(rel_id); if v_violation_msg is not null then - v_violation_p := ''t''; + v_violation_p := 't'; end if; if v_violation_p != expect_violation_p then @@ -81,36 +90,44 @@ from acs_rels where rel_id = rel_constraint_test_check.rel_id; - str := ''Relation '' || acs_object_name(rel_id) || - '' ('' || rel_id || '')'' || - '' failed (violation_p = '' || v_violation_p || ''). '' || - ''Rel info: type = '' || v_rel_type || - '', object one = '' || + str := 'Relation ' || acs_object_name(rel_id) || + ' (' || rel_id || ')' || + ' failed (violation_p = ' || v_violation_p || '). ' || + '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; end if; return null; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- creates blah_member_rel and yippe_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; @@ -139,54 +156,54 @@ 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'); - 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. - reg_users := acs__magic_object_id(''registered_users''); + reg_users := acs__magic_object_id('registered_users'); rel_id := composition_rel__new(A, B); rel_id := composition_rel__new(A, C); @@ -204,14 +221,14 @@ side_two_constraint := rel_constraint__new( null, - ''rel_constraint'', - ''Yippe: side 2 must be a blah of A'', + 'rel_constraint', + 'Yippe: side 2 must be a blah of A', rel_segment__get_or_new(reg_users, - ''yippe_member_rel'', + 'yippe_member_rel', null), - ''two'', + 'two', rel_segment__get_or_new(A, - ''blah_member_rel'', + 'blah_member_rel', null), null, null, @@ -222,14 +239,14 @@ side_one_constraint := rel_constraint__new( null, - ''rel_constraint'', - ''Yippe: side 1 must be a component of E'', + 'rel_constraint', + 'Yippe: side 1 must be a component of E', rel_segment__get_or_new(reg_users, - ''yippe_member_rel'', + 'yippe_member_rel', null), - ''one'', + 'one', rel_segment__get_or_new(E, - ''composition_rel'', + 'composition_rel', null), null, null, @@ -248,42 +265,42 @@ -- joe is a blah of A, and F is component of E, so its legal to make joe -- a yippe of F. - rel_id := blah_member_rel__new(null, ''blah_member_rel'', A, joe); + rel_id := blah_member_rel__new(null, 'blah_member_rel', A, joe); - PERFORM rel_constraint_test_check(rel_id, ''f''); + PERFORM rel_constraint_test_check(rel_id, 'f'); - rel_id := yippe_member_rel__new(null, ''yippie_member_rel'', F, joe); + rel_id := yippe_member_rel__new(null, 'yippie_member_rel', F, joe); - PERFORM rel_constraint_test_check(rel_id, ''f''); + PERFORM rel_constraint_test_check(rel_id, 'f'); -- do constraints respect group hierarchy? If so, this will be legal: - rel_id := blah_member_rel__new(null, ''blah_member_rel'', B, jane); + rel_id := blah_member_rel__new(null, 'blah_member_rel', B, jane); - PERFORM rel_constraint_test_check(rel_id, ''f''); + PERFORM rel_constraint_test_check(rel_id, 'f'); - rel_id := yippe_member_rel__new(null, ''yippie_member_rel'', F, jane); + rel_id := yippe_member_rel__new(null, 'yippie_member_rel', F, jane); - PERFORM rel_constraint_test_check(rel_id, ''f''); + PERFORM rel_constraint_test_check(rel_id, 'f'); -- ILLEGAL MEMBERSHIPS: -- G is not a component of F, therefore no one can be a yippe of G -- This should violated 2 constraints (object one and object two are both -- invalid). - rel_id := yippe_member_rel__new(null, ''yippie_member_rel'', G, bob); + rel_id := yippe_member_rel__new(null, 'yippie_member_rel', G, bob); - PERFORM rel_constraint_test_check(rel_id, ''t''); + PERFORM rel_constraint_test_check(rel_id, 't'); -- betty is not a blah of A, therefore she cannot be a yippe of F. - rel_id := yippe_member_rel__new(null, ''yippie_member_rel'', F, betty); + rel_id := yippe_member_rel__new(null, 'yippie_member_rel', F, betty); - PERFORM rel_constraint_test_check(rel_id, ''t''); + PERFORM rel_constraint_test_check(rel_id, 't'); -- make sven be a regular member of A. Sven cannot be a yippe of F. rel_id := membership_rel__new(A, sven); - rel_id := yippe_member_rel__new(null, ''yippie_member_rel'', F, sven); + rel_id := yippe_member_rel__new(null, 'yippie_member_rel', F, sven); - PERFORM rel_constraint_test_check(rel_id, ''t''); + PERFORM rel_constraint_test_check(rel_id, 't'); -- TEST THE VIEWS (there should be 4 violated constraints, -- 1 side one violation and 3 side two violations. @@ -292,7 +309,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; @@ -301,7 +318,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; @@ -321,9 +338,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,''yippe_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,'yippe_member_rel')); -- Remove the test groups. PERFORM acs_group__delete(G); @@ -346,7 +363,8 @@ return null; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select test_rel_constraints(); Index: openacs-4/packages/acs-kernel/sql/test/rel-segments-test-types-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/test/rel-segments-test-types-create.sql,v diff -u -r1.3 -r1.4 --- openacs-4/packages/acs-kernel/sql/test/rel-segments-test-types-create.sql 30 Apr 2001 01:34:02 -0000 1.3 +++ openacs-4/packages/acs-kernel/sql/test/rel-segments-test-types-create.sql 30 Mar 2013 19:32:40 -0000 1.4 @@ -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 ( - ''yippe_member_rel'', - ''Yippe Membership Relationship'', - ''Yippe Membership Relationships'', - ''membership_rel'', - ''yippe_member_rels'', - ''rel_id'', - ''yippe_member_rel'', - ''group'', + 'yippe_member_rel', + 'Yippe Membership Relationship', + 'Yippe Membership Relationships', + 'membership_rel', + 'yippe_member_rels', + 'rel_id', + 'yippe_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 yippe_member_rel -- function new -create function yippe_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('yippe_member_rel__new','rel_id,rel_type,object_id_one,object_id_two'); + +-- +-- procedure yippe_member_rel__new/4 +-- +CREATE OR REPLACE FUNCTION yippe_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 yippe_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 ); @@ -183,22 +209,32 @@ return v_rel_id; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- procedure delete -create function yippe_member_rel__delete (yippe_member_rels) -returns integer as ' -declare - delete__rel_id alias for $1; -begin + +-- added +select define_function_args('yippe_member_rel__delete','rel_id'); + +-- +-- procedure yippe_member_rel__delete/1 +-- +CREATE OR REPLACE FUNCTION yippe_member_rel__delete( + delete__rel_id yippe_member_rels +) RETURNS integer AS $$ +DECLARE +BEGIN + delete from yippe_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/test/rel-segments-test.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/test/rel-segments-test.sql,v diff -u -r1.3 -r1.4 --- openacs-4/packages/acs-kernel/sql/test/rel-segments-test.sql 30 Apr 2001 01:34:02 -0000 1.3 +++ openacs-4/packages/acs-kernel/sql/test/rel-segments-test.sql 30 Mar 2013 19:32:40 -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,27 +57,35 @@ if NOT v_pass_p then - str := ''Row missing from rel_segment_party_map for'' || - '' segment '''''' || acs_object.name(segment_id) || - '''''' ('' || segment_id || '')'' || - '', party '''''' || acs_object.name(party_id) || - '''''' ('' || party_id || '')'' || - '', container '''''' || acs_object.name(container_id) || - '''''' ('' ||container_id || '')''; + str := 'Row missing from rel_segment_party_map for' || + ' segment ''' || acs_object.name(segment_id) || + ''' (' || segment_id || ')' || + ', party ''' || acs_object.name(party_id) || + ''' (' || party_id || ')' || + ', container ''' || acs_object.name(container_id) || + ''' (' ||container_id || ')'; - raise NOTICE ''%'', str; + raise NOTICE '%', str; - acs_log.error(''rel_segment_test_check'', str); + 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; @@ -91,51 +107,51 @@ seg_E_yippes 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. @@ -149,54 +165,62 @@ -- Make a couple of memberships. - rel_id := blah_member_rel__new(null, ''blah_member_rel'', B, joe); - rel_id := yippe_member_rel__new(null, ''yippie_member_rel'', B, jane); - rel_id := blah_member_rel__new(null, ''blah_member_rel'', B, betty); - rel_id := yippe_member_rel__new(null, ''yippie_member_rel'', A, bob); - rel_id := blah_member_rel__new(null, ''blah_member_rel'', A, betty); - rel_id := yippe_member_rel__new(null, ''yippie_member_rel'', E, betty); + rel_id := blah_member_rel__new(null, 'blah_member_rel', B, joe); + rel_id := yippe_member_rel__new(null, 'yippie_member_rel', B, jane); + rel_id := blah_member_rel__new(null, 'blah_member_rel', B, betty); + rel_id := yippe_member_rel__new(null, 'yippie_member_rel', A, bob); + rel_id := blah_member_rel__new(null, 'blah_member_rel', A, betty); + rel_id := yippe_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 yippe members of E seg_E_yippes := rel_segment__new(null, - ''rel_segment'', + 'rel_segment', now(), null, null, null, null, - ''Yippes of Group E'', + 'Yippes of Group E', E, - ''yippe_member_rel'', + 'yippe_member_rel', null ); - insert into groups_test_segs values (seg_G_blahs,1,''seg_G_blahs''); - insert into groups_test_segs values (seg_E_yippes,2,''seg_E_yippes''); + insert into groups_test_segs values (seg_G_blahs,1,'seg_G_blahs'); + insert into groups_test_segs values (seg_E_yippes,2,'seg_E_yippes'); 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; @@ -220,32 +244,32 @@ 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 gname = ''joe''; - select user_id into jane from groups_test_users where gname = ''jane''; - select user_id into bob from groups_test_users where gname = ''bob''; - select user_id into betty from groups_test_users where gname = ''betty''; - select user_id into jack from groups_test_users where gname = ''jack''; - select user_id into jill from groups_test_users where gname = ''jill''; - select user_id into sven from groups_test_users where gname = ''sven''; - select user_id into stacy from groups_test_users where gname = ''stacy''; + select user_id into joe from groups_test_users where gname = 'joe'; + select user_id into jane from groups_test_users where gname = 'jane'; + select user_id into bob from groups_test_users where gname = 'bob'; + select user_id into betty from groups_test_users where gname = 'betty'; + select user_id into jack from groups_test_users where gname = 'jack'; + select user_id into jill from groups_test_users where gname = 'jill'; + select user_id into sven from groups_test_users where gname = 'sven'; + select user_id into stacy from groups_test_users where gname = '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_yippes from groups_test_segs - where sname = ''seg_G_blahs''; + where sname = 'seg_G_blahs'; -- group_element_index_dump; -- rel_segment_party_map_dump; @@ -256,80 +280,80 @@ -- 2. seg_E_yippes 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_yippes contains jane with container B - if rel_segment_test_check(seg_E_yippes, jane, B) = ''f'' then - str := ''Segment '' || acs_object__name(seg_E_yippes) || - ''('' || seg_E_yippes || '') failed. Group_id = '' + if rel_segment_test_check(seg_E_yippes, jane, B) = 'f' then + str := 'Segment ' || acs_object__name(seg_E_yippes) || + '(' || seg_E_yippes || ') failed. Group_id = ' || E; - raise NOTICE ''%'', str; + raise NOTICE '%', str; end if; -- check: seg_E_yippes contains bob with container A - if rel_segment_test_check(seg_E_yippes, bob, A) = ''f'' then - str := ''Segment '' || acs_object__name(seg_E_yippes) || - ''('' || seg_E_yippes || '') failed. Group_id = '' + if rel_segment_test_check(seg_E_yippes, bob, A) = 'f' then + str := 'Segment ' || acs_object__name(seg_E_yippes) || + '(' || seg_E_yippes || ') failed. Group_id = ' || E; - raise NOTICE ''%'', str; + raise NOTICE '%', str; end if; -- check: seg_E_yippes contains betty with container E - if rel_segment_test_check(seg_E_yippes, betty, E) = ''f'' then - str := ''Segment '' || acs_object__name(seg_E_yippes) || - ''('' || seg_E_yippes || '') failed. Group_id = '' + if rel_segment_test_check(seg_E_yippes, betty, E) = 'f' then + str := 'Segment ' || acs_object__name(seg_E_yippes) || + '(' || seg_E_yippes || ') 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( - rel_segment__get_or_new(F,''membership_rel''), 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; + rel_segment__get_or_new(F,'membership_rel'), 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( - rel_segment__get_or_new(F,''membership_rel''), 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; + rel_segment__get_or_new(F,'membership_rel'), 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_yippes); - 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 @@ -361,7 +385,8 @@ return null; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select test_segs(); select check_segs(); Index: openacs-4/packages/acs-subsite/tcl/package-procs-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-subsite/tcl/package-procs-postgresql.xql,v diff -u -r1.18 -r1.19 --- openacs-4/packages/acs-subsite/tcl/package-procs-postgresql.xql 13 Sep 2009 23:54:41 -0000 1.18 +++ openacs-4/packages/acs-subsite/tcl/package-procs-postgresql.xql 30 Mar 2013 19:32:40 -0000 1.19 @@ -208,12 +208,12 @@ perform define_function_args('${package_name}__new','[plpgsql_utility::define_function_args $attribute_list]'); -create function ${package_name}__new([plpgsql_utility::generate_function_signature $attribute_list]) -returns [plpgsql_utility::table_column_type ${table_name} ${id_column}] as ' -declare +CREATE FUNCTION ${package_name}__new([plpgsql_utility::generate_function_signature $attribute_list]) +RETURNS [plpgsql_utility::table_column_type ${table_name} ${id_column}] AS \$\$ +DECLARE [plpgsql_utility::generate_attribute_parameters $attribute_list]; v_$id_column ${table_name}.${id_column}%TYPE; -begin +BEGIN v_$id_column := ${supertype_package_name}__new ( [plpgsql_utility::generate_attribute_parameter_call_from_attributes \ @@ -229,18 +229,20 @@ return v_$id_column; -end;' language 'plpgsql'; +END; +\$\$ LANGUAGE plpgsql; -create function ${package_name}__delete ([plpgsql_utility::table_column_type ${table_name} ${id_column}]) -returns integer as ' -declare - p_${id_column} alias for [plpgsql_utility::dollar]1; -begin +CREATE FUNCTION ${package_name}__delete ( + p_${id_column} [plpgsql_utility::table_column_type ${table_name} ${id_column}] +) RETURNS integer AS \$\$ +DECLARE +BEGIN perform ${supertype_package_name}__delete( p_${id_column} ); return 1; -end;' language 'plpgsql'; +END; +\$\$ LANGUAGE plpgsql; return null; end;