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();
