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;
 
 
 
