Index: openacs-4/packages/acs-service-contract/sql/postgresql/acs-sc-msg-types-create.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-service-contract/sql/postgresql/acs-sc-msg-types-create.sql,v
diff -u -r1.8 -r1.9
--- openacs-4/packages/acs-service-contract/sql/postgresql/acs-sc-msg-types-create.sql	8 Jun 2007 17:44:17 -0000	1.8
+++ openacs-4/packages/acs-service-contract/sql/postgresql/acs-sc-msg-types-create.sql	30 Mar 2013 17:40:53 -0000	1.9
@@ -42,22 +42,27 @@
 -- register function record
 select define_function_args('acs_sc_msg_type__new','msg_type_name,msg_type_spec');
 -- declare function
-create or replace function acs_sc_msg_type__new(varchar,varchar)
-returns integer as '
-declare
-    p_msg_type_name             alias for $1;
-    p_msg_type_spec		alias for $2;
+
+
+--
+-- procedure acs_sc_msg_type__new/2
+--
+CREATE OR REPLACE FUNCTION acs_sc_msg_type__new(
+   p_msg_type_name varchar,
+   p_msg_type_spec varchar
+) RETURNS integer AS $$
+DECLARE
     v_msg_type_id               integer;
-begin
+BEGIN
 
     v_msg_type_id := acs_object__new(
                 null,
-                ''acs_sc_msg_type'',
+                'acs_sc_msg_type',
                 now(),
                 null,
                 null,
                 null,
-                ''t'',
+                't',
                 p_msg_type_name,
                 null
             );
@@ -74,76 +79,105 @@
 
     return v_msg_type_id;
 
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 -- register function record
 select define_function_args('acs_sc_msg_type__get_id','msg_type_name');
 -- declare function
-create or replace function acs_sc_msg_type__get_id(varchar)
-returns integer as '
-declare
-    p_msg_type_name		alias for $1;
+
+
+--
+-- procedure acs_sc_msg_type__get_id/1
+--
+CREATE OR REPLACE FUNCTION acs_sc_msg_type__get_id(
+   p_msg_type_name varchar
+) RETURNS integer AS $$
+DECLARE
     v_msg_type_id		integer;
-begin
+BEGIN
 
     select msg_type_id into v_msg_type_id
     from acs_sc_msg_types
     where msg_type_name = p_msg_type_name;
    
     return v_msg_type_id;
 
-end;' language 'plpgsql' stable strict;
+END;
+$$ LANGUAGE plpgsql stable strict;
 
 -- register function record
 select define_function_args('acs_sc_msg_type__get_name','msg_type_id');
 -- declare function
-create or replace function acs_sc_msg_type__get_name(integer)
-returns varchar as '
-declare
-    p_msg_type_id		alias for $1;
+
+
+--
+-- procedure acs_sc_msg_type__get_name/1
+--
+CREATE OR REPLACE FUNCTION acs_sc_msg_type__get_name(
+   p_msg_type_id integer
+) RETURNS varchar AS $$
+DECLARE
     v_msg_type_name		varchar;
-begin
+BEGIN
 
     select msg_type_name into v_msg_type_name
     from acs_sc_msg_types
     where msg_type_id = p_msg_type_id;
    
     return v_msg_type_name;
 
-end;' language 'plpgsql' stable strict;
+END;
+$$ LANGUAGE plpgsql stable strict;
 
-create or replace function acs_sc_msg_type__delete(integer)
-returns integer as '
-declare
-    p_msg_type_id		alias for $1;
-begin
 
+
+--
+-- procedure acs_sc_msg_type__delete/1
+--
+CREATE OR REPLACE FUNCTION acs_sc_msg_type__delete(
+   p_msg_type_id integer
+) RETURNS integer AS $$
+DECLARE
+BEGIN
+
     delete from acs_sc_msg_types
     where msg_type_id = p_msg_type_id;
 
     return 0;
 
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 -- XXX: this might be a bug that it does not return 0 as the above does.
 -- anyway now it is strict as being called with null is a noop and returns null
 -- register function record
-select define_function_args('acs_sc_msg_type__delete','msg_type_name');
+
+-- old define_function_args('acs_sc_msg_type__delete','msg_type_name')
+-- new
+select define_function_args('acs_sc_msg_type__delete','msg_type_id');
+
 -- declare function
-create or replace function acs_sc_msg_type__delete(varchar)
-returns integer as '
-declare
-    p_msg_type_name		alias for $1;
+
+
+--
+-- procedure acs_sc_msg_type__delete/1
+--
+CREATE OR REPLACE FUNCTION acs_sc_msg_type__delete(
+   p_msg_type_name varchar
+) RETURNS integer AS $$
+DECLARE
     v_msg_type_id		integer;
-begin
+BEGIN
 
     v_msg_type_id := acs_sc_msg_type__get_id(p_msg_type_name);
 
     perform acs_sc_msg_type__delete(v_msg_type_id);
 
     return v_msg_type_id;
 
-end;' language 'plpgsql' strict;
+END;
+$$ LANGUAGE plpgsql strict;
 
 
 
@@ -152,28 +186,34 @@
 -- register function record
 select define_function_args('acs_sc_msg_type__new_element','msg_type_name,element_name,element_msg_type_name,element_msg_type_isset_p;f,element_pos');
 -- declare function
-create or replace function acs_sc_msg_type__new_element(varchar,varchar,varchar,boolean,integer)
-returns integer as '
-declare
-    p_msg_type_name		alias for $1;
-    p_element_name		alias for $2;
-    p_element_msg_type_name	alias for $3;
-    p_element_msg_type_isset_p	alias for $4;
-    p_element_pos		alias for $5;
+
+
+--
+-- procedure acs_sc_msg_type__new_element/5
+--
+CREATE OR REPLACE FUNCTION acs_sc_msg_type__new_element(
+   p_msg_type_name varchar,
+   p_element_name varchar,
+   p_element_msg_type_name varchar,
+   p_element_msg_type_isset_p boolean, -- default 'f'
+   p_element_pos integer
+
+) RETURNS integer AS $$
+DECLARE
     v_msg_type_id		integer;
     v_element_msg_type_id	integer;
-begin
+BEGIN
 
     v_msg_type_id := acs_sc_msg_type__get_id(p_msg_type_name);
 
     if v_msg_type_id is null then
-        raise exception ''Unknown Message Type: %'', p_msg_type_name;
+        raise exception 'Unknown Message Type: %', p_msg_type_name;
     end if;
 
     v_element_msg_type_id := acs_sc_msg_type__get_id(p_element_msg_type_name);
 
     if v_element_msg_type_id is null then
-        raise exception ''Unknown Message Type: %'', p_element_msg_type_name;
+        raise exception 'Unknown Message Type: %', p_element_msg_type_name;
     end if;
 
     insert into acs_sc_msg_type_elements (
@@ -192,50 +232,56 @@
 
     return v_msg_type_id;
 
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 
 
 -- register function record
 select define_function_args('acs_sc_msg_type__parse_spec','msg_type_name,msg_type_spec');
 -- declare function
-create or replace function acs_sc_msg_type__parse_spec(varchar,varchar)
-returns integer as '
-declare
-    p_msg_type_name		alias for $1;
-    p_msg_type_spec		alias for $2;
+
+
+--
+-- procedure acs_sc_msg_type__parse_spec/2
+--
+CREATE OR REPLACE FUNCTION acs_sc_msg_type__parse_spec(
+   p_msg_type_name varchar,
+   p_msg_type_spec varchar
+) RETURNS integer AS $$
+DECLARE
     v_element			varchar;
     v_element_type		varchar;
     v_str_pos			integer;
     v_element_name		varchar;
     v_element_msg_type_name	varchar;
     v_element_msg_type_isset_p	boolean;
     v_element_pos		integer;
-begin
+BEGIN
 
     v_element_pos := 1;
-    v_element := split(p_msg_type_spec, '','', v_element_pos);
+    v_element := split(p_msg_type_spec, ',', v_element_pos);
 
     while v_element is not null loop
 
-        v_str_pos = instr(v_element, '':'', 1, 1);
+        v_str_pos = instr(v_element, ':', 1, 1);
 
 	if v_str_pos > 0 then
 	    v_element_name := trim(substr(v_element, 1, v_str_pos-1));
 	    v_element_type := trim(substr(v_element, v_str_pos+1, length(v_element) - v_str_pos));
-	    if (instr(v_element_type, ''['',1,1) = length(v_element_type)-1) and 
-	       (instr(v_element_type, '']'',1,1) = length(v_element_type)) then
-	        v_element_msg_type_isset_p := ''t'';
+	    if (instr(v_element_type, '[',1,1) = length(v_element_type)-1) and 
+	       (instr(v_element_type, ']',1,1) = length(v_element_type)) then
+	        v_element_msg_type_isset_p := 't';
 	        v_element_msg_type_name := trim(substr(v_element_type,1,length(v_element_type)-2));
-		if v_element_msg_type_name = '''' then
-		    raise exception ''Wrong Format: Message Type Specification'';
+		if v_element_msg_type_name = '' then
+		    raise exception 'Wrong Format: Message Type Specification';
 		end if;
 	    else
-	        v_element_msg_type_isset_p := ''f'';
+	        v_element_msg_type_isset_p := 'f';
 	        v_element_msg_type_name := v_element_type;
 	    end if;
         else
-	    raise exception ''Wrong Format: Message Type Specification'';
+	    raise exception 'Wrong Format: Message Type Specification';
         end if;
 
         perform acs_sc_msg_type__new_element(
@@ -247,13 +293,14 @@
         );
 
         v_element_pos := v_element_pos + 1;
-	v_element := split(p_msg_type_spec, '','', v_element_pos);
+	v_element := split(p_msg_type_spec, ',', v_element_pos);
 
     end loop;
 
     return v_element_pos-1;
 
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 
 
