Index: openacs-4/packages/acs-kernel/sql/postgresql/apm-create.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/postgresql/apm-create.sql,v
diff -u -r1.74 -r1.75
--- openacs-4/packages/acs-kernel/sql/postgresql/apm-create.sql	31 Oct 2010 00:15:01 -0000	1.74
+++ openacs-4/packages/acs-kernel/sql/postgresql/apm-create.sql	7 Jul 2011 10:46:02 -0000	1.75
@@ -95,25 +95,25 @@
   request processor.
 ';
 
-create or replace function inline_0 ()
-returns integer as '
-begin
+CREATE OR REPLACE FUNCTION inline_0 () RETURNS integer AS $$
+BEGIN
 -- Create a new object type for packages.
  PERFORM acs_object_type__create_type (
-   ''apm_package'',         -- object_type
-   ''Package'',             -- pretty_name
-   ''Packages'',            -- pretty_plural
-   ''acs_object'',          -- supertype
-   ''apm_packages'',        -- table_name
-   ''package_id'',          -- id_column
-   ''apm_package'',         -- package_name
-   ''f'',                   -- abstract_p
-   ''apm_package_types'',   -- type_extension_table
-   ''apm_package__name''     -- name_method
+   'apm_package',         -- object_type
+   'Package',             -- pretty_name
+   'Packages',            -- pretty_plural
+   'acs_object',          -- supertype
+   'apm_packages',        -- table_name
+   'package_id',          -- id_column
+   'apm_package',         -- package_name
+   'f',                   -- abstract_p
+   'apm_package_types',   -- type_extension_table
+   'apm_package__name'     -- name_method
    );
 
   return 0;
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 select inline_0 ();
 
@@ -122,30 +122,37 @@
 
 -- show errors
 
-create or replace function inline_1 ()
-returns integer as '
-declare
+
+
+--
+-- procedure inline_1/0
+--
+CREATE OR REPLACE FUNCTION inline_1(
+
+) RETURNS integer AS $$
+DECLARE
  attr_id acs_attributes.attribute_id%TYPE;
-begin
+BEGIN
 -- Register the meta-data for APM-packages
  attr_id := acs_attribute__create_attribute (
-   ''apm_package'',
-   ''package_key'',
-   ''string'',
-   ''Package Key'',
-   ''Package Keys'',
+   'apm_package',
+   'package_key',
+   'string',
+   'Package Key',
+   'Package Keys',
    null,
    null,
    null,
    1,
    1,
    null,
-   ''type_specific'',
-   ''f''
+   'type_specific',
+   'f'
    );
 
   return 0;
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 select inline_1 ();
 
@@ -377,234 +384,241 @@
 
 -- Metadata for the apm_package_versions object.
 
-create or replace function inline_2 ()
-returns integer as '
-declare
+
+
+--
+-- procedure inline_2/0
+--
+CREATE OR REPLACE FUNCTION inline_2(
+
+) RETURNS integer AS $$
+DECLARE
  attr_id acs_attributes.attribute_id%TYPE;
-begin
+BEGIN
  attr_id := acs_object_type__create_type (
-   ''apm_package_version'',
-   ''Package Version'',
-   ''Package Versions'',
-   ''acs_object'',
-   ''apm_package_versions'',
-   ''version_id'',
-   ''apm_package_version'',
-   ''f'',
+   'apm_package_version',
+   'Package Version',
+   'Package Versions',
+   'acs_object',
+   'apm_package_versions',
+   'version_id',
+   'apm_package_version',
+   'f',
    null,
    null
    );
 
  attr_id := acs_attribute__create_attribute (
-   ''apm_package_version'',
-   ''package_key'',
-   ''string'',
-   ''Package Key'',
-   ''Package Keys'',
+   'apm_package_version',
+   'package_key',
+   'string',
+   'Package Key',
+   'Package Keys',
    null,
    null,
    null,
    1,
    1,
    null,
-   ''type_specific'',
-   ''f''
+   'type_specific',
+   'f'
    );
 
  attr_id := acs_attribute__create_attribute (
-   ''apm_package_version'',
-   ''version_name'',
-   ''string'',
-   ''Version Name'',
-   ''Version Names'',
+   'apm_package_version',
+   'version_name',
+   'string',
+   'Version Name',
+   'Version Names',
    null,
    null,
    null,
    1,
    1,
    null,
-   ''type_specific'',
-   ''f''
+   'type_specific',
+   'f'
    );
 
  attr_id := acs_attribute__create_attribute (
-   ''apm_package_version'',
-   ''version_uri'',
-   ''string'',
-   ''Version URI'',
-   ''Version URIs'',
+   'apm_package_version',
+   'version_uri',
+   'string',
+   'Version URI',
+   'Version URIs',
    null,
    null,
    null,
    1,
    1,
    null,
-   ''type_specific'',
-   ''f''
+   'type_specific',
+   'f'
    );
 
  attr_id := acs_attribute__create_attribute (
-   ''apm_package_version'',
-   ''summary'',
-   ''string'',
-   ''Summary'',
-   ''Summaries'',
+   'apm_package_version',
+   'summary',
+   'string',
+   'Summary',
+   'Summaries',
    null,
    null,
    null,
    1,
    1,
    null,
-   ''type_specific'',
-   ''f''
+   'type_specific',
+   'f'
    );
 
  attr_id := acs_attribute__create_attribute (
-   ''apm_package_version'',
-   ''description_format'',
-   ''string'',
-   ''Description Format'',
-   ''Description Formats'',
+   'apm_package_version',
+   'description_format',
+   'string',
+   'Description Format',
+   'Description Formats',
    null,
    null,
    null,
    1,
    1,
    null,
-   ''type_specific'',
-   ''f''
+   'type_specific',
+   'f'
    );
 
  attr_id := acs_attribute__create_attribute (
-   ''apm_package_version'',
-   ''description'',
-   ''string'',
-   ''Description'',
-   ''Descriptions'',
+   'apm_package_version',
+   'description',
+   'string',
+   'Description',
+   'Descriptions',
    null,
    null,
    null,
    1,
    1,
    null,
-   ''type_specific'',
-   ''f''
+   'type_specific',
+   'f'
    );
 
  attr_id := acs_attribute__create_attribute (
-   ''apm_package_version'',
-   ''vendor'',
-   ''string'',
-   ''Vendor'',
-   ''Vendors'',
+   'apm_package_version',
+   'vendor',
+   'string',
+   'Vendor',
+   'Vendors',
    null,
    null,
    null,
    1,
    1,
    null,
-   ''type_specific'',
-   ''f''
+   'type_specific',
+   'f'
    );
 
  attr_id := acs_attribute__create_attribute (
-   ''apm_package_version'',
-   ''vendor_uri'',
-   ''string'',
-   ''Vendor URI'',
-   ''Vendor URIs'',
+   'apm_package_version',
+   'vendor_uri',
+   'string',
+   'Vendor URI',
+   'Vendor URIs',
    null,
    null,
    null,
    1,
    1,
    null,
-   ''type_specific'',
-   ''f''
+   'type_specific',
+   'f'
    );
 
  attr_id := acs_attribute__create_attribute (
-   ''apm_package_version'',
-   ''enabled_p'',
-   ''boolean'',
-   ''Enabled'',
-   ''Enabled'',
+   'apm_package_version',
+   'enabled_p',
+   'boolean',
+   'Enabled',
+   'Enabled',
    null,
    null,
    null,
    1,
    1,
    null,
-   ''type_specific'',
-   ''f''
+   'type_specific',
+   'f'
    );
 
  attr_id := acs_attribute__create_attribute (
-   ''apm_package_version'',
-   ''activation_date'',
-   ''date'',
-   ''Activation Date'',
-   ''Activation Dates'',
+   'apm_package_version',
+   'activation_date',
+   'date',
+   'Activation Date',
+   'Activation Dates',
    null,
    null,
    null,
    1,
    1,
    null,
-   ''type_specific'',
-   ''f''
+   'type_specific',
+   'f'
    );
 
  attr_id := acs_attribute__create_attribute (
-   ''apm_package_version'',
-   ''deactivation_date'',
-   ''date'',
-   ''Deactivation Date'',
-   ''Deactivation Dates'',
+   'apm_package_version',
+   'deactivation_date',
+   'date',
+   'Deactivation Date',
+   'Deactivation Dates',
    null,
    null,
    null,
    1,
    1,
    null,
-   ''type_specific'',
-   ''f''
+   'type_specific',
+   'f'
    );
 
  attr_id := acs_attribute__create_attribute (
-   ''apm_package_version'',
-   ''distribution_uri'',
-   ''string'',
-   ''Distribution URI'',
-   ''Distribution URIs'',
+   'apm_package_version',
+   'distribution_uri',
+   'string',
+   'Distribution URI',
+   'Distribution URIs',
    null,
    null,
    null,
    1,
    1,
    null,
-   ''type_specific'',
-   ''f''
+   'type_specific',
+   'f'
    );
 
  attr_id := acs_attribute__create_attribute (
-   ''apm_package_version'',
-   ''distribution_date'',
-   ''date'',
-   ''Distribution Date'',
-   ''Distribution Dates'',
+   'apm_package_version',
+   'distribution_date',
+   'date',
+   'Distribution Date',
+   'Distribution Dates',
    null,
    null,
    null,
    1,
    1,
    null,
-   ''type_specific'',
-   ''f''
+   'type_specific',
+   'f'
    );
 
   return 0;
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 select inline_2 ();
 
@@ -797,138 +811,145 @@
 
 -- Metadata for the apm_parameter and apm_parameter_value system.
 
-create or replace function inline_4 ()
-returns integer as '
-declare
+
+
+--
+-- procedure inline_4/0
+--
+CREATE OR REPLACE FUNCTION inline_4(
+
+) RETURNS integer AS $$
+DECLARE
  attr_id acs_attributes.attribute_id%TYPE;
-begin
+BEGIN
  attr_id := acs_object_type__create_type (
-   ''apm_parameter'',
-   ''Package Parameter'',
-   ''Package Parameters'',
-   ''acs_object'',
-   ''apm_parameters'',
-   ''parameter_id'',
-   ''apm_parameter'',
-   ''f'',
+   'apm_parameter',
+   'Package Parameter',
+   'Package Parameters',
+   'acs_object',
+   'apm_parameters',
+   'parameter_id',
+   'apm_parameter',
+   'f',
    null,
    null
    );
 
  attr_id := acs_attribute__create_attribute (
-   ''apm_parameter'',
-   ''package_key'',
-   ''string'',
-   ''Package Key'',
-   ''Package Keys'',
+   'apm_parameter',
+   'package_key',
+   'string',
+   'Package Key',
+   'Package Keys',
    null,
    null,
    null,
    1,
    1,
    null,
-   ''type_specific'',
-   ''f''
+   'type_specific',
+   'f'
    );
 
  attr_id := acs_attribute__create_attribute (
-   ''apm_parameter'',
-   ''parameter_name'',
-   ''string'',
-   ''Parameter Name'',
-   ''Parameter Name'',
+   'apm_parameter',
+   'parameter_name',
+   'string',
+   'Parameter Name',
+   'Parameter Name',
    null,
    null,
    null,
    1,
    1,
    null,
-   ''type_specific'',
-   ''f''
+   'type_specific',
+   'f'
    );
 
 attr_id := acs_attribute__create_attribute (
-   ''apm_parameter'',
-   ''scope'',
-   ''string'',
-   ''Scope'',
-   ''Scope'',
+   'apm_parameter',
+   'scope',
+   'string',
+   'Scope',
+   'Scope',
    null,
    null,
    null,
    1,
    1,
    null,
-   ''type_specific'',
-   ''f''
+   'type_specific',
+   'f'
    ); 
 
  attr_id := acs_attribute__create_attribute (
-   ''apm_parameter'',
-   ''datatype'',
-   ''string'',
-   ''Datatype'',
-   ''Datatypes'',
+   'apm_parameter',
+   'datatype',
+   'string',
+   'Datatype',
+   'Datatypes',
    null,
    null,
    null,
    1,
    1,
    null,
-   ''type_specific'',
-   ''f''
+   'type_specific',
+   'f'
    );
 
  attr_id := acs_attribute__create_attribute (
-   ''apm_parameter'',
-   ''default_value'',
-   ''string'',
-   ''Default Value'',
-   ''Default Values'',
+   'apm_parameter',
+   'default_value',
+   'string',
+   'Default Value',
+   'Default Values',
    null,
    null,
    null,
    1,
    1,
    null,
-   ''type_specific'',
-   ''f''
+   'type_specific',
+   'f'
    );
 
  attr_id := acs_attribute__create_attribute (
-   ''apm_parameter'',
-   ''min_n_values'',
-   ''number'',
-   ''Minimum Number of Values'',
-   ''Minimum Numer of Values Settings'',
+   'apm_parameter',
+   'min_n_values',
+   'number',
+   'Minimum Number of Values',
+   'Minimum Numer of Values Settings',
    null,
    null,
    1,
    1,
    1,
    null,
-   ''type_specific'',
-   ''f''
+   'type_specific',
+   'f'
    );
 
  attr_id := acs_attribute__create_attribute (
-   ''apm_parameter'',
-   ''max_n_values'',
-   ''integer'',
-   ''Maximum Number of Values'',
-   ''Maximum Number of Values Settings'',
+   'apm_parameter',
+   'max_n_values',
+   'integer',
+   'Maximum Number of Values',
+   'Maximum Number of Values Settings',
    null,
    null,
    1,
    1,
    1,
    null,
-   ''type_specific'',
-   ''f''
+   'type_specific',
+   'f'
    );
 
   return 0;
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 select inline_4 ();
 
@@ -938,74 +959,81 @@
 -- show errors
 
 
-create or replace function inline_5 ()
-returns integer as '
-declare
+
+
+--
+-- procedure inline_5/0
+--
+CREATE OR REPLACE FUNCTION inline_5(
+
+) RETURNS integer AS $$
+DECLARE
  attr_id acs_attributes.attribute_id%TYPE;
-begin
+BEGIN
  attr_id := acs_object_type__create_type (
-   ''apm_parameter_value'',
-   ''APM Package Parameter Value'',
-   ''APM Package Parameter Values'',
-   ''acs_object'',
-   ''apm_parameter_values'',
-   ''value_id'',
-   ''apm_parameter_value'',
-   ''f'',
+   'apm_parameter_value',
+   'APM Package Parameter Value',
+   'APM Package Parameter Values',
+   'acs_object',
+   'apm_parameter_values',
+   'value_id',
+   'apm_parameter_value',
+   'f',
    null,
    null
    );
 
  attr_id := acs_attribute__create_attribute (
-   ''apm_parameter_value'',
-   ''package_id'',
-   ''number'',
-   ''Package ID'',
-   ''Package IDs'',
+   'apm_parameter_value',
+   'package_id',
+   'number',
+   'Package ID',
+   'Package IDs',
    null,
    null,
    null,
    1,
    1,
    null,
-   ''type_specific'',
-   ''f''
+   'type_specific',
+   'f'
    );
 
  attr_id := acs_attribute__create_attribute (
-   ''apm_parameter_value'',
-   ''parameter_id'',
-   ''number'',
-   ''Parameter ID'',
-   ''Parameter IDs'',
+   'apm_parameter_value',
+   'parameter_id',
+   'number',
+   'Parameter ID',
+   'Parameter IDs',
    null,
    null,
    null,
    1,
    1,
    null,
-   ''type_specific'',
-   ''f''
+   'type_specific',
+   'f'
    );
 
  attr_id := acs_attribute__create_attribute (
-   ''apm_parameter_value'',
-   ''attr_value'',
-   ''string'',
-   ''Parameter Value'',
-   ''Parameter Values'',
+   'apm_parameter_value',
+   'attr_value',
+   'string',
+   'Parameter Value',
+   'Parameter Values',
    null,
    null,
    null,
    1,
    1,
    null,
-   ''type_specific'',
-   ''f''
+   'type_specific',
+   'f'
    );
 
   return 0;
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 select inline_5 ();
 
@@ -1063,27 +1091,34 @@
 ';
 
 
-create or replace function inline_6 ()
-returns integer as '
-declare 
+
+
+--
+-- procedure inline_6/0
+--
+CREATE OR REPLACE FUNCTION inline_6(
+
+) RETURNS integer AS $$
+DECLARE 
         dummy   integer;
-begin
+BEGIN
 -- Create a new object type for applications.
  dummy :=  acs_object_type__create_type (
-   ''apm_application'',
-   ''Application'',
-   ''Applications'',
-   ''apm_package'',
-   ''apm_applications'',
-   ''application_id'',
-   ''apm_application'',
-   ''f'',
+   'apm_application',
+   'Application',
+   'Applications',
+   'apm_package',
+   'apm_applications',
+   'application_id',
+   'apm_application',
+   'f',
    null,
    null
    );
 
   return 0;
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 select inline_6 ();
 
@@ -1093,47 +1128,63 @@
 -- show errors
 
 
-create or replace function inline_7 ()
-returns integer as '
-declare
+
+
+--
+-- procedure inline_7/0
+--
+CREATE OR REPLACE FUNCTION inline_7(
+
+) RETURNS integer AS $$
+DECLARE
         dummy   integer;
-begin
+BEGIN
 -- Create a new object type for services.
  dummy := acs_object_type__create_type (
-   ''apm_service'',
-   ''Service'',
-   ''Services'',
-   ''apm_package'',
-   ''apm_services'',
-   ''service_id'',
-   ''apm_service'',
-   ''f'',
+   'apm_service',
+   'Service',
+   'Services',
+   'apm_package',
+   'apm_services',
+   'service_id',
+   'apm_service',
+   'f',
    null,
    null
    );
 
   return 0;
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 select inline_7 ();
 
 drop function inline_7 ();
 
-create or replace function apm__register_package (varchar,varchar,varchar,varchar,varchar,boolean,boolean,boolean,boolean,varchar,integer)
-returns integer as '
-declare
-  package_key            alias for $1;  
-  pretty_name            alias for $2;  
-  pretty_plural          alias for $3;  
-  package_uri            alias for $4;  
-  package_type           alias for $5;  
-  initial_install_p      alias for $6;  -- default ''f''  
-  singleton_p            alias for $7;  -- default ''f''  
-  implements_subsite_p   alias for $8;  -- default ''f''  
-  inherit_templates_p    alias for $9;  -- default ''f''  
-  spec_file_path         alias for $10;  -- default null
-  spec_file_mtime        alias for $11;  -- default null
-begin
+
+
+-- added
+select define_function_args('apm__register_package','package_key,pretty_name,pretty_plural,package_uri,package_type,initial_install_p;f,singleton_p;f,implements_subsite_p;f,inherit_templates_p;f,spec_file_path;null,spec_file_mtime;null');
+
+--
+-- procedure apm__register_package/11
+--
+CREATE OR REPLACE FUNCTION apm__register_package(
+   package_key varchar,
+   pretty_name varchar,
+   pretty_plural varchar,
+   package_uri varchar,
+   package_type varchar,
+   initial_install_p boolean,    -- default 'f'
+   singleton_p boolean,          -- default 'f'
+   implements_subsite_p boolean, -- default 'f'
+   inherit_templates_p boolean,  -- default 'f'
+   spec_file_path varchar,       -- default null
+   spec_file_mtime integer       -- default null
+
+) RETURNS integer AS $$
+DECLARE
+BEGIN
     PERFORM apm_package_type__create_type(
     	package_key,
 	pretty_name,
@@ -1149,24 +1200,34 @@
     );
 
     return 0; 
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 -- function update_package
-create or replace function apm__update_package (varchar,varchar,varchar,varchar,varchar,boolean,boolean,boolean,boolean,varchar,integer)
-returns varchar as '
-declare
-  package_key            alias for $1;  
-  pretty_name            alias for $2;  -- default null
-  pretty_plural          alias for $3;  -- default null  
-  package_uri            alias for $4;  -- default null  
-  package_type           alias for $5;  -- default null  
-  initial_install_p      alias for $6;  -- default null  
-  singleton_p            alias for $7;  -- default null  
-  implements_subsite_p   alias for $8;  -- default ''f''  
-  inherit_templates_p    alias for $9;  -- default ''f''  
-  spec_file_path         alias for $10;  -- default null
-  spec_file_mtime        alias for $11;  -- default null
-begin
+
+
+-- added
+select define_function_args('apm__update_package','package_key,pretty_name;null,pretty_plural;null,package_uri;null,package_type;null,initial_install_p;null,singleton_p;null,implements_subsite_p;f,inherit_templates_p;f,spec_file_path;null,spec_file_mtime;null');
+
+--
+-- procedure apm__update_package/11
+--
+CREATE OR REPLACE FUNCTION apm__update_package(
+   package_key varchar,
+   pretty_name varchar,          -- default null
+   pretty_plural varchar,        -- default null
+   package_uri varchar,          -- default null
+   package_type varchar,         -- default null
+   initial_install_p boolean,    -- default null
+   singleton_p boolean,          -- default null
+   implements_subsite_p boolean, -- default 'f'
+   inherit_templates_p boolean,  -- default 'f'
+   spec_file_path varchar,       -- default null
+   spec_file_mtime integer       -- default null
+
+) RETURNS varchar AS $$
+DECLARE
+BEGIN
  
     return apm_package_type__update_type(
     	package_key,
@@ -1181,18 +1242,28 @@
 	spec_file_path,
 	spec_file_mtime
     );
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 -- procedure unregister_package
-create or replace function apm__unregister_package (varchar,boolean)
-returns integer as '
-declare
-  package_key            alias for $1;  
-  p_cascade_p            alias for $2;  -- default ''t''  
+
+
+-- added
+select define_function_args('apm__unregister_package','package_key,cascade_p;t');
+
+--
+-- procedure apm__unregister_package/2
+--
+CREATE OR REPLACE FUNCTION apm__unregister_package(
+   package_key varchar,
+   p_cascade_p boolean -- default 't'
+
+) RETURNS integer AS $$
+DECLARE
   v_cascade_p            boolean;
-begin
+BEGIN
    if cascade_p is null then 
-	v_cascade_p := ''t'';
+	v_cascade_p := 't';
    else 
        v_cascade_p := p_cascade_p;
    end if;
@@ -1203,46 +1274,65 @@
    );
 
    return 0; 
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 
 -- function register_p
-create or replace function apm__register_p (varchar)
-returns integer as '
-declare
-  register_p__package_key            alias for $1;  
+
+
+-- added
+select define_function_args('apm__register_p','package_key');
+
+--
+-- procedure apm__register_p/1
+--
+CREATE OR REPLACE FUNCTION apm__register_p(
+   register_p__package_key varchar
+) RETURNS integer AS $$
+DECLARE
   v_register_p                       integer;       
-begin
+BEGIN
     select case when count(*) = 0 then 0 else 1 end into v_register_p 
     from apm_package_types 
     where package_key = register_p__package_key;
 
     return v_register_p;
    
-end;' language 'plpgsql' stable;
+END;
+$$ LANGUAGE plpgsql stable;
 
 
 -- procedure register_application
-create or replace function apm__register_application (varchar,varchar,varchar,varchar,boolean,boolean,boolean,boolean,varchar,integer)
-returns integer as '
-declare
-  package_key            alias for $1;  
-  pretty_name            alias for $2;  
-  pretty_plural          alias for $3;  
-  package_uri            alias for $4;  
-  initial_install_p      alias for $5;  -- default ''f'' 
-  singleton_p            alias for $6;  -- default ''f'' 
-  implements_subsite_p   alias for $7;  -- default ''f''  
-  inherit_templates_p    alias for $8;  -- default ''f''  
-  spec_file_path         alias for $9;  -- default null
-  spec_file_mtime        alias for $10;  -- default null
-begin
+
+
+-- added
+select define_function_args('apm__register_application','package_key,pretty_name,pretty_plural,package_uri,initial_install_p;f,singleton_p;f,implements_subsite_p;f,inherit_templates_p;f,spec_file_path;null,spec_file_mtime;null');
+
+--
+-- procedure apm__register_application/10
+--
+CREATE OR REPLACE FUNCTION apm__register_application(
+   package_key varchar,
+   pretty_name varchar,
+   pretty_plural varchar,
+   package_uri varchar,
+   initial_install_p boolean,    -- default 'f'
+   singleton_p boolean,          -- default 'f'
+   implements_subsite_p boolean, -- default 'f'
+   inherit_templates_p boolean,  -- default 'f'
+   spec_file_path varchar,       -- default null
+   spec_file_mtime integer       -- default null
+
+) RETURNS integer AS $$
+DECLARE
+BEGIN
    PERFORM apm__register_package(
 	package_key,
 	pretty_name,
 	pretty_plural,
 	package_uri,
-	''apm_application'',
+	'apm_application',
 	initial_install_p,
 	singleton_p,
         implements_subsite_p,
@@ -1252,19 +1342,29 @@
    ); 
 
    return 0; 
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 
 -- procedure unregister_application
-create or replace function apm__unregister_application (varchar,boolean)
-returns integer as '
-declare
-  package_key            alias for $1;  
-  p_cascade_p              alias for $2;  -- default ''f''  
+
+
+-- added
+select define_function_args('apm__unregister_application','package_key,cascade_p;f');
+
+--
+-- procedure apm__unregister_application/2
+--
+CREATE OR REPLACE FUNCTION apm__unregister_application(
+   package_key varchar,
+   p_cascade_p boolean -- default 'f'
+
+) RETURNS integer AS $$
+DECLARE
   v_cascade_p            boolean;
-begin
+BEGIN
    if p_cascade_p is null then 
-	v_cascade_p := ''f'';
+	v_cascade_p := 'f';
    else 
        v_cascade_p := p_cascade_p;
    end if;
@@ -1275,30 +1375,40 @@
    );
 
    return 0; 
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 
 -- procedure register_service
-create or replace function apm__register_service (varchar,varchar,varchar,varchar,boolean,boolean,boolean,boolean,varchar,integer)
-returns integer as '
-declare
-  package_key            alias for $1;  
-  pretty_name            alias for $2;  
-  pretty_plural          alias for $3;  
-  package_uri            alias for $4;  
-  initial_install_p      alias for $5;  -- default ''f''  
-  singleton_p            alias for $6;  -- default ''f''  
-  implements_subsite_p   alias for $7;  -- default ''f''  
-  inherit_templates_p    alias for $8;  -- default ''f''  
-  spec_file_path         alias for $9;  -- default null
-  spec_file_mtime        alias for $10;  -- default null
-begin
+
+
+-- added
+select define_function_args('apm__register_service','package_key,pretty_name,pretty_plural,package_uri,initial_install_p;f,singleton_p;f,implements_subsite_p;f,inherit_templates_p;f,spec_file_path;null,spec_file_mtime;null');
+
+--
+-- procedure apm__register_service/10
+--
+CREATE OR REPLACE FUNCTION apm__register_service(
+   package_key varchar,
+   pretty_name varchar,
+   pretty_plural varchar,
+   package_uri varchar,
+   initial_install_p boolean,    -- default 'f'
+   singleton_p boolean,          -- default 'f'
+   implements_subsite_p boolean, -- default 'f'
+   inherit_templates_p boolean,  -- default 'f'
+   spec_file_path varchar,       -- default null
+   spec_file_mtime integer       -- default null
+
+) RETURNS integer AS $$
+DECLARE
+BEGIN
    PERFORM apm__register_package(
 	package_key,
 	pretty_name,
 	pretty_plural,
 	package_uri,
-	''apm_service'',
+	'apm_service',
 	initial_install_p,
 	singleton_p,
         implements_subsite_p,
@@ -1308,19 +1418,29 @@
    );  
  
    return 0; 
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 
 -- procedure unregister_service
-create or replace function apm__unregister_service (varchar,boolean)
-returns integer as '
-declare
-  package_key           alias for $1;  
-  p_cascade_p           alias for $2;  -- default ''f''  
+
+
+-- added
+select define_function_args('apm__unregister_service','package_key,cascade_p;f');
+
+--
+-- procedure apm__unregister_service/2
+--
+CREATE OR REPLACE FUNCTION apm__unregister_service(
+   package_key varchar,
+   p_cascade_p boolean -- default 'f'
+
+) RETURNS integer AS $$
+DECLARE
   v_cascade_p           boolean;
-begin
+BEGIN
    if p_cascade_p is null then 
-	v_cascade_p := ''f'';
+	v_cascade_p := 'f';
    else 
 	v_cascade_p := p_cascade_p;
    end if;
@@ -1331,37 +1451,47 @@
    );
 
    return 0; 
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
-create or replace function apm__register_parameter (integer,varchar,varchar,varchar,varchar,varchar,varchar,varchar,integer,integer)
-returns integer as '
-declare
-  register_parameter__parameter_id           alias for $1;  -- default null  
-  register_parameter__package_key            alias for $2;  
-  register_parameter__parameter_name         alias for $3;  
-  register_parameter__description            alias for $4;  -- default null  
-  register_parameter__scope                  alias for $5;  
-  register_parameter__datatype               alias for $6;  -- default ''string''  
-  register_parameter__default_value          alias for $7;  -- default null  
-  register_parameter__section_name           alias for $8;  -- default null 
-  register_parameter__min_n_values           alias for $9;  -- default 1
-  register_parameter__max_n_values           alias for $10;  -- default 1
 
+
+-- added
+select define_function_args('apm__register_parameter','parameter_id;null,package_key,parameter_name,description;null,scope,datatype;string,default_value;null,section_name;null,min_n_values;1,max_n_values;1');
+
+--
+-- procedure apm__register_parameter/10
+--
+CREATE OR REPLACE FUNCTION apm__register_parameter(
+   register_parameter__parameter_id integer,  -- default null
+   register_parameter__package_key varchar,
+   register_parameter__parameter_name varchar,
+   register_parameter__description varchar,   -- default null
+   register_parameter__scope varchar,
+   register_parameter__datatype varchar,      -- default 'string'
+   register_parameter__default_value varchar, -- default null
+   register_parameter__section_name varchar,  -- default null
+   register_parameter__min_n_values integer,  -- default 1
+   register_parameter__max_n_values integer   -- default 1
+
+) RETURNS integer AS $$
+DECLARE
+
   v_parameter_id         apm_parameters.parameter_id%TYPE;
   v_value_id             apm_parameter_values.value_id%TYPE;
   v_pkg                  record;
 
-begin
+BEGIN
     -- Create the new parameter.    
     v_parameter_id := acs_object__new(
        register_parameter__parameter_id,
-       ''apm_parameter'',
+       'apm_parameter',
        now(),
        null,
        null,
        null,
-       ''t'',
-       register_parameter__package_key || '' - '' || register_parameter__parameter_name,
+       't',
+       register_parameter__package_key || ' - ' || register_parameter__parameter_name,
        null
     );
     
@@ -1376,7 +1506,7 @@
      register_parameter__max_n_values);
 
     -- Propagate parameter to new instances.	
-    if register_parameter__scope = ''instance'' then
+    if register_parameter__scope = 'instance' then
       for v_pkg in
           select package_id
   	from apm_packages
@@ -1398,45 +1528,62 @@
 	
     return v_parameter_id;
    
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 -- For backwards compatibility, register a parameter with "instance" scope.
 
-create or replace function apm__register_parameter (integer,varchar,varchar,varchar,varchar,varchar,varchar,integer,integer)
-returns integer as '
-declare
-  register_parameter__parameter_id           alias for $1;  -- default null  
-  register_parameter__package_key            alias for $2;  
-  register_parameter__parameter_name         alias for $3;  
-  register_parameter__description            alias for $4;  -- default null  
-  register_parameter__datatype               alias for $5;  -- default ''string''  
-  register_parameter__default_value          alias for $6;  -- default null  
-  register_parameter__section_name           alias for $7;  -- default null 
-  register_parameter__min_n_values           alias for $8;  -- default 1
-  register_parameter__max_n_values           alias for $9;  -- default 1
 
-begin
+
+--
+-- procedure apm__register_parameter/9
+--
+CREATE OR REPLACE FUNCTION apm__register_parameter(
+   register_parameter__parameter_id integer,  -- default null
+   register_parameter__package_key varchar,
+   register_parameter__parameter_name varchar,
+   register_parameter__description varchar,   -- default null
+   register_parameter__datatype varchar,      -- default 'string'
+   register_parameter__default_value varchar, -- default null
+   register_parameter__section_name varchar,  -- default null
+   register_parameter__min_n_values integer,  -- default 1
+   register_parameter__max_n_values integer   -- default 1
+
+) RETURNS integer AS $$
+DECLARE
+
+BEGIN
   return
     apm__register_parameter(register_parameter__parameter_id, register_parameter__package_key,
                            register_parameter__parameter_name, register_parameter__description,
-                           ''instance'',  register_parameter__datatype,
+                           'instance',  register_parameter__datatype,
                            register_parameter__default_value, register_parameter__section_name,
                            register_parameter__min_n_values, register_parameter__max_n_values);
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 -- function update_parameter
-create or replace function apm__update_parameter (integer,varchar,varchar,varchar,varchar,varchar,integer,integer)
-returns varchar as '
-declare
-  update_parameter__parameter_id           alias for $1;  
-  update_parameter__parameter_name         alias for $2;  -- default null  
-  update_parameter__description            alias for $3;  -- default null
-  update_parameter__datatype               alias for $4;  -- default ''string''
-  update_parameter__default_value          alias for $5;  -- default null
-  update_parameter__section_name           alias for $6;  -- default null
-  update_parameter__min_n_values           alias for $7;  -- default 1
-  update_parameter__max_n_values           alias for $8;  -- default 1
-begin
+
+
+-- added
+select define_function_args('apm__update_parameter','parameter_id,parameter_name;null,description;null,datatype;string,default_value;null,section_name;null,min_n_values;1,max_n_values;1');
+
+--
+-- procedure apm__update_parameter/8
+--
+CREATE OR REPLACE FUNCTION apm__update_parameter(
+   update_parameter__parameter_id integer,
+   update_parameter__parameter_name varchar, -- default null
+   update_parameter__description varchar,    -- default null
+   update_parameter__datatype varchar,       -- default 'string'
+   update_parameter__default_value varchar,  -- default null
+   update_parameter__section_name varchar,   -- default null
+   update_parameter__min_n_values integer,   -- default 1
+   update_parameter__max_n_values integer    -- default 1
+
+) RETURNS varchar AS $$
+DECLARE
+BEGIN
     update apm_parameters 
 	set parameter_name = coalesce(update_parameter__parameter_name, parameter_name),
             default_value  = coalesce(update_parameter__default_value, default_value),
@@ -1448,56 +1595,83 @@
       where parameter_id = update_parameter__parameter_id;
 
     update acs_objects
-       set title = (select package_key || '': Parameter '' || parameter_name
+       set title = (select package_key || ': Parameter ' || parameter_name
                     from apm_parameters
                     where parameter_id = update_parameter__parameter_id)
      where object_id = update_parameter__parameter_id;
 
     return parameter_id;
      
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 
 -- function parameter_p
-create or replace function apm__parameter_p (varchar,varchar)
-returns integer as '
-declare
-  parameter_p__package_key            alias for $1;  
-  parameter_p__parameter_name         alias for $2;  
+
+
+-- added
+select define_function_args('apm__parameter_p','package_key,parameter_name');
+
+--
+-- procedure apm__parameter_p/2
+--
+CREATE OR REPLACE FUNCTION apm__parameter_p(
+   parameter_p__package_key varchar,
+   parameter_p__parameter_name varchar
+) RETURNS integer AS $$
+DECLARE
   v_parameter_p                       integer;       
-begin
+BEGIN
     select case when count(*) = 0 then 0 else 1 end into v_parameter_p 
     from apm_parameters
     where package_key = parameter_p__package_key
     and parameter_name = parameter_p__parameter_name;
 
     return v_parameter_p;
    
-end;' language 'plpgsql' stable;
+END;
+$$ LANGUAGE plpgsql stable;
 
 
 -- procedure unregister_parameter
-create or replace function apm__unregister_parameter (integer)
-returns integer as '
-declare
-  unregister_parameter__parameter_id           alias for $1;  -- default null
-begin
+
+
+-- added
+select define_function_args('apm__unregister_parameter','parameter_id;null');
+
+--
+-- procedure apm__unregister_parameter/1
+--
+CREATE OR REPLACE FUNCTION apm__unregister_parameter(
+   unregister_parameter__parameter_id integer -- default null
+
+) RETURNS integer AS $$
+DECLARE
+BEGIN
     delete from apm_parameter_values 
     where parameter_id = unregister_parameter__parameter_id;
     delete from apm_parameters 
     where parameter_id = unregister_parameter__parameter_id;
     PERFORM acs_object__delete(unregister_parameter__parameter_id);
 
     return 0; 
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
-create or replace function apm__id_for_name (integer,varchar)
-returns integer as '
-declare
-  id_for_name__package_id             alias for $1;  
-  id_for_name__parameter_name         alias for $2;  
+
+
+-- added
+
+--
+-- procedure apm__id_for_name/2
+--
+CREATE OR REPLACE FUNCTION apm__id_for_name(
+   id_for_name__package_id integer,
+   id_for_name__parameter_name varchar
+) RETURNS integer AS $$
+DECLARE
   a_parameter_id                      apm_parameters.parameter_id%TYPE;
-begin
+BEGIN
     select parameter_id into a_parameter_id 
     from apm_parameters 
     where parameter_name = id_for_name__parameter_name
@@ -1506,42 +1680,59 @@
 
     if NOT FOUND
       then
-      	raise EXCEPTION ''-20000: The specified package % AND/OR parameter % do not exist in the system'', id_for_name__package_id, id_for_name__parameter_name;
+      	raise EXCEPTION '-20000: The specified package % AND/OR parameter % do not exist in the system', id_for_name__package_id, id_for_name__parameter_name;
     end if;
 
     return a_parameter_id;
    
-end;' language 'plpgsql' stable strict;
+END;
+$$ LANGUAGE plpgsql stable strict;
 
-create or replace function apm__id_for_name (varchar,varchar)
-returns integer as '
-declare
-  id_for_name__package_key            alias for $1;  
-  id_for_name__parameter_name         alias for $2;  
+
+
+-- added
+select define_function_args('apm__id_for_name','package_key,parameter_name');
+
+--
+-- procedure apm__id_for_name/2
+--
+CREATE OR REPLACE FUNCTION apm__id_for_name(
+   id_for_name__package_key varchar,
+   id_for_name__parameter_name varchar
+) RETURNS integer AS $$
+DECLARE
   a_parameter_id                      apm_parameters.parameter_id%TYPE;
-begin
+BEGIN
     select parameter_id into a_parameter_id
     from apm_parameters p
     where p.parameter_name = id_for_name__parameter_name and
           p.package_key = id_for_name__package_key;
 
     if NOT FOUND
       then
-      	raise EXCEPTION ''-20000: The specified package % AND/OR parameter % do not exist in the system'', id_for_name__package_key, id_for_name__parameter_name;
+      	raise EXCEPTION '-20000: The specified package % AND/OR parameter % do not exist in the system', id_for_name__package_key, id_for_name__parameter_name;
     end if;
 
     return a_parameter_id;
    
-end;' language 'plpgsql' stable strict;
+END;
+$$ LANGUAGE plpgsql stable strict;
 
-create or replace function apm__get_value (integer,varchar)
-returns varchar as '
-declare
-  get_value__package_id             alias for $1;  
-  get_value__parameter_name         alias for $2;  
+
+
+-- added
+
+--
+-- procedure apm__get_value/2
+--
+CREATE OR REPLACE FUNCTION apm__get_value(
+   get_value__package_id integer,
+   get_value__parameter_name varchar
+) RETURNS varchar AS $$
+DECLARE
   v_parameter_id                    apm_parameter_values.parameter_id%TYPE;
   value                             apm_parameter_values.attr_value%TYPE;
-begin
+BEGIN
     v_parameter_id := apm__id_for_name (get_value__package_id, get_value__parameter_name);
 
     select attr_value into value from apm_parameter_values v
@@ -1550,16 +1741,25 @@
 
     return value;
    
-end;' language 'plpgsql' stable strict;
+END;
+$$ LANGUAGE plpgsql stable strict;
 
-create or replace function apm__get_value (varchar,varchar)
-returns varchar as '
-declare
-  get_value__package_key            alias for $1;  
-  get_value__parameter_name         alias for $2;  
+
+
+-- added
+select define_function_args('apm__get_value','package_key,parameter_name');
+
+--
+-- procedure apm__get_value/2
+--
+CREATE OR REPLACE FUNCTION apm__get_value(
+   get_value__package_key varchar,
+   get_value__parameter_name varchar
+) RETURNS varchar AS $$
+DECLARE
   v_parameter_id                    apm_parameter_values.parameter_id%TYPE;
   value                             apm_parameter_values.attr_value%TYPE;
-begin
+BEGIN
     v_parameter_id := apm__id_for_name (get_value__package_key, get_value__parameter_name);
 
     select attr_value into value from apm_parameter_values v
@@ -1568,17 +1768,25 @@
 
     return value;
    
-end;' language 'plpgsql' stable strict;
+END;
+$$ LANGUAGE plpgsql stable strict;
 
-create or replace function apm__set_value (integer,varchar,varchar)
-returns integer as '
-declare
-  set_value__package_id             alias for $1;  
-  set_value__parameter_name         alias for $2;  
-  set_value__attr_value             alias for $3;  
+
+
+-- added
+
+--
+-- procedure apm__set_value/3
+--
+CREATE OR REPLACE FUNCTION apm__set_value(
+   set_value__package_id integer,
+   set_value__parameter_name varchar,
+   set_value__attr_value varchar
+) RETURNS integer AS $$
+DECLARE
   v_parameter_id                    apm_parameter_values.parameter_id%TYPE;
   v_value_id                        apm_parameter_values.value_id%TYPE;
-begin
+BEGIN
     v_parameter_id := apm__id_for_name (set_value__package_id, set_value__parameter_name);
 
     -- Determine if the value exists
@@ -1601,17 +1809,26 @@
      end if;
 
     return 0; 
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
-create or replace function apm__set_value (varchar,varchar,varchar)
-returns integer as '
-declare
-  set_value__package_key            alias for $1;  
-  set_value__parameter_name         alias for $2;  
-  set_value__attr_value             alias for $3;  
+
+
+-- added
+select define_function_args('apm__set_value','package_key,parameter_name,attr_value');
+
+--
+-- procedure apm__set_value/3
+--
+CREATE OR REPLACE FUNCTION apm__set_value(
+   set_value__package_key varchar,
+   set_value__parameter_name varchar,
+   set_value__attr_value varchar
+) RETURNS integer AS $$
+DECLARE
   v_parameter_id                    apm_parameter_values.parameter_id%TYPE;
   v_value_id                        apm_parameter_values.value_id%TYPE;
-begin
+BEGIN
     v_parameter_id := apm__id_for_name (set_value__package_key, set_value__parameter_name);
 
     -- Determine if the value exists
@@ -1634,49 +1851,68 @@
      end if;
 
     return 0; 
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
-create or replace function apm_package__is_child(varchar, varchar) returns boolean as '
-declare
-  parent_package_key       alias for $1;
-  child_package_key        alias for $2;
+
+
+-- added
+select define_function_args('apm_package__is_child','parent_package_key,child_package_key');
+
+--
+-- procedure apm_package__is_child/2
+--
+CREATE OR REPLACE FUNCTION apm_package__is_child(
+   parent_package_key varchar,
+   child_package_key varchar
+) RETURNS boolean AS $$
+DECLARE
   dependency               record;
-begin
+BEGIN
 
   if parent_package_key = child_package_key then
-    return ''t'';
+    return 't';
   end if;
 
   for dependency in 
     select apd.service_uri
     from apm_package_versions apv, apm_package_dependencies apd
     where apd.version_id = apv.version_id
       and apv.enabled_p
-      and apd.dependency_type in (''embeds'', ''extends'')
+      and apd.dependency_type in ('embeds', 'extends')
       and apv.package_key = child_package_key
   loop
     if dependency.service_uri = parent_package_key or
       apm_package__is_child(parent_package_key, dependency.service_uri) then
-      return ''t'';
+      return 't';
     end if;
   end loop;
       
-  return ''f'';
-end;' language 'plpgsql';
+  return 'f';
+END;
+$$ LANGUAGE plpgsql;
 
-create or replace function apm_package__initialize_parameters (integer,varchar)
-returns integer as '
-declare
-  ip__package_id             alias for $1;  
-  ip__package_key            alias for $2;  
+
+
+-- added
+select define_function_args('apm_package__initialize_parameters','package_id,package_key');
+
+--
+-- procedure apm_package__initialize_parameters/2
+--
+CREATE OR REPLACE FUNCTION apm_package__initialize_parameters(
+   ip__package_id integer,
+   ip__package_key varchar
+) RETURNS integer AS $$
+DECLARE
   v_value_id                 apm_parameter_values.value_id%TYPE;
   cur_val                    record;
-begin
+BEGIN
     -- need to initialize all params for this type
     for cur_val in select parameter_id, default_value
        from apm_parameters
        where package_key = ip__package_key
-         and scope = ''instance''
+         and scope = 'instance'
       loop
         v_value_id := apm_parameter_value__new(
           null,
@@ -1687,27 +1923,37 @@
       end loop;   
 
       return 0; 
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 
 -- function new
-create or replace function apm_package__new (integer,varchar,varchar,varchar,timestamptz,integer,varchar,integer)
-returns integer as '
-declare
-  new__package_id             alias for $1;  -- default null  
-  new__instance_name          alias for $2;  -- default null
-  new__package_key            alias for $3;  
-  new__object_type            alias for $4;  -- default ''apm_package''
-  new__creation_date          alias for $5;  -- default now()
-  new__creation_user          alias for $6;  -- default null
-  new__creation_ip            alias for $7;  -- default null
-  new__context_id             alias for $8;  -- default null
+
+
+-- added
+select define_function_args('apm_package__new','package_id;null,instance_name;null,package_key,object_type;apm_package,creation_date;now(),creation_user;null,creation_ip;null,context_id;null');
+
+--
+-- procedure apm_package__new/8
+--
+CREATE OR REPLACE FUNCTION apm_package__new(
+   new__package_id integer,        -- default null
+   new__instance_name varchar,     -- default null
+   new__package_key varchar,
+   new__object_type varchar,       -- default 'apm_package'
+   new__creation_date timestamptz, -- default now()
+   new__creation_user integer,     -- default null
+   new__creation_ip varchar,       -- default null
+   new__context_id integer         -- default null
+
+) RETURNS integer AS $$
+DECLARE
   v_singleton_p               integer;       
   v_package_type              apm_package_types.package_type%TYPE;
   v_num_instances             integer;       
   v_package_id                apm_packages.package_id%TYPE;
   v_instance_name             apm_packages.instance_name%TYPE;
-begin
+BEGIN
    v_singleton_p := apm_package__singleton_p(
 			new__package_key
 		    );
@@ -1730,8 +1976,8 @@
 	  new__creation_ip,
 	  new__context_id
 	 );
-       if new__instance_name is null or new__instance_name = '''' then 
-	 v_instance_name := new__package_key || '' '' || v_package_id;
+       if new__instance_name is null or new__instance_name = '' then 
+	 v_instance_name := new__package_key || ' ' || v_package_id;
        else
 	 v_instance_name := new__instance_name;
        end if;
@@ -1750,7 +1996,7 @@
            package_id = v_package_id
        where object_id = v_package_id;
 
-       if v_package_type = ''apm_application'' then
+       if v_package_type = 'apm_application' then
 	   insert into apm_applications
 	   (application_id)
 	   values
@@ -1770,14 +2016,24 @@
        return v_package_id;
 
   end if;
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
   
-create or replace function apm_package__delete (integer) returns integer as '
-declare
-   delete__package_id   alias for $1;
+
+
+-- added
+select define_function_args('apm_package__delete','package_id');
+
+--
+-- procedure apm_package__delete/1
+--
+CREATE OR REPLACE FUNCTION apm_package__delete(
+   delete__package_id integer
+) RETURNS integer AS $$
+DECLARE
    cur_val              record;
    v_folder_row         record;
-begin
+BEGIN
     -- Delete all parameters.
     for cur_val in select value_id from apm_parameter_values
 	where package_id = delete__package_id loop
@@ -1790,7 +2046,7 @@
         from cr_folders
         where package_id = delete__package_id
     loop
-        perform content_folder__del(v_folder_row.folder_id,''t'');
+        perform content_folder__del(v_folder_row.folder_id,'t');
     end loop;
 
     delete from apm_applications where application_id = delete__package_id;
@@ -1808,70 +2064,120 @@
     );   
 
     return 0;
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
-create or replace function apm_package__initial_install_p (varchar) returns integer as '
-declare
-	initial_install_p__package_key  alias for $1;
+
+
+-- added
+select define_function_args('apm_package__initial_install_p','package_key');
+
+--
+-- procedure apm_package__initial_install_p/1
+--
+CREATE OR REPLACE FUNCTION apm_package__initial_install_p(
+   initial_install_p__package_key varchar
+) RETURNS integer AS $$
+DECLARE
         v_initial_install_p             integer;
-begin
+BEGIN
         select 1 into v_initial_install_p
 	from apm_package_types
 	where package_key = initial_install_p__package_key
-        and initial_install_p = ''t'';
+        and initial_install_p = 't';
 	
         if NOT FOUND then 
            return 0;
         else
            return v_initial_install_p;
         end if;
-end;' language 'plpgsql' stable;
+END;
+$$ LANGUAGE plpgsql stable;
 
-create or replace function apm_package__singleton_p (varchar) returns integer as '
-declare
-	singleton_p__package_key        alias for $1;
+
+
+-- added
+select define_function_args('apm_package__singleton_p','package_key');
+
+--
+-- procedure apm_package__singleton_p/1
+--
+CREATE OR REPLACE FUNCTION apm_package__singleton_p(
+   singleton_p__package_key varchar
+) RETURNS integer AS $$
+DECLARE
         v_singleton_p                   integer;
-begin
+BEGIN
         select count(*) into v_singleton_p
 	from apm_package_types
 	where package_key = singleton_p__package_key
-        and singleton_p = ''t'';
+        and singleton_p = 't';
 
         return v_singleton_p;
-end;' language 'plpgsql' stable;
+END;
+$$ LANGUAGE plpgsql stable;
 
-create or replace function apm_package__num_instances (varchar) returns integer as '
-declare
-        num_instances__package_key     alias for $1;
+
+
+-- added
+select define_function_args('apm_package__num_instances','package_key');
+
+--
+-- procedure apm_package__num_instances/1
+--
+CREATE OR REPLACE FUNCTION apm_package__num_instances(
+   num_instances__package_key varchar
+) RETURNS integer AS $$
+DECLARE
         v_num_instances                integer;
-begin
+BEGIN
         select count(*) into v_num_instances
 	from apm_packages
 	where package_key = num_instances__package_key;
 
         return v_num_instances;
 
-end;' language 'plpgsql' stable;
+END;
+$$ LANGUAGE plpgsql stable;
 
-create or replace function apm_package__name (integer) returns varchar as '
-declare
-    name__package_id       alias for $1;
+
+
+-- added
+select define_function_args('apm_package__name','package_id');
+
+--
+-- procedure apm_package__name/1
+--
+CREATE OR REPLACE FUNCTION apm_package__name(
+   name__package_id integer
+) RETURNS varchar AS $$
+DECLARE
     v_result               apm_packages.instance_name%TYPE;
-begin
+BEGIN
     select instance_name into v_result
     from apm_packages
     where package_id = name__package_id;
 
     return v_result;
 
-end;' language 'plpgsql' stable strict;
+END;
+$$ LANGUAGE plpgsql stable strict;
 
-create or replace function apm_package__highest_version (varchar) returns integer as '
-declare
-     highest_version__package_key    alias for $1;
+
+
+-- added
+select define_function_args('apm_package__highest_version','package_key');
+
+--
+-- procedure apm_package__highest_version/1
+--
+CREATE OR REPLACE FUNCTION apm_package__highest_version(
+   highest_version__package_key varchar
+) RETURNS integer AS $$
+DECLARE
      v_version_id                    apm_package_versions.version_id%TYPE;
      v_max_version                   varchar;
-begin
+BEGIN
      select max(apm_package_version__sortable_version_name(v.version_name)) into v_max_version 
        from apm_package_version_info v where v.package_key = highest_version__package_key;
 
@@ -1883,13 +2189,23 @@
       else
          return v_version_id;
       end if;
-end;' language 'plpgsql' stable;
+END;
+$$ LANGUAGE plpgsql stable;
 
-create or replace function apm_package__parent_id (integer) returns integer as '
-declare
-    apm_package__parent_id__package_id alias for $1;
+
+
+-- added
+select define_function_args('apm_package__parent_id','parent_id__package_id');
+
+--
+-- procedure apm_package__parent_id/1
+--
+CREATE OR REPLACE FUNCTION apm_package__parent_id(
+   apm_package__parent_id__package_id integer
+) RETURNS integer AS $$
+DECLARE
     v_package_id apm_packages.package_id%TYPE;
-begin
+BEGIN
     select sn1.object_id
     into v_package_id
     from site_nodes sn1
@@ -1899,28 +2215,39 @@
 
     return v_package_id;
 
-end;' language 'plpgsql' stable strict;
+END;
+$$ LANGUAGE plpgsql stable strict;
 
 -- create or replace package body apm_package_version 
-create or replace function apm_package_version__new (integer,varchar,varchar,varchar,varchar,varchar,varchar,timestamptz,varchar,varchar,varchar,boolean,boolean) returns integer as '
-declare
-      apm_pkg_ver__version_id           alias for $1;  -- default null
-      apm_pkg_ver__package_key		alias for $2;
-      apm_pkg_ver__version_name		alias for $3;  -- default null
-      apm_pkg_ver__version_uri		alias for $4;
-      apm_pkg_ver__summary              alias for $5;
-      apm_pkg_ver__description_format	alias for $6;
-      apm_pkg_ver__description		alias for $7;
-      apm_pkg_ver__release_date		alias for $8;
-      apm_pkg_ver__vendor               alias for $9;
-      apm_pkg_ver__vendor_uri		alias for $10;
-      apm_pkg_ver__auto_mount           alias for $11;
-      apm_pkg_ver__installed_p		alias for $12; -- default ''f''		
-      apm_pkg_ver__data_model_loaded_p	alias for $13; -- default ''f''
+
+
+-- added
+select define_function_args('apm_package_version__new','version_id;null,package_key,version_name;null,version_uri,summary,description_format,description,release_date,vendor,vendor_uri,auto_mount,installed_p;f,data_model_loaded_p;f');
+
+--
+-- procedure apm_package_version__new/13
+--
+CREATE OR REPLACE FUNCTION apm_package_version__new(
+   apm_pkg_ver__version_id integer,         -- default null
+   apm_pkg_ver__package_key varchar,
+   apm_pkg_ver__version_name varchar,       -- default null
+   apm_pkg_ver__version_uri varchar,
+   apm_pkg_ver__summary varchar,
+   apm_pkg_ver__description_format varchar,
+   apm_pkg_ver__description varchar,
+   apm_pkg_ver__release_date timestamptz,
+   apm_pkg_ver__vendor varchar,
+   apm_pkg_ver__vendor_uri varchar,
+   apm_pkg_ver__auto_mount varchar,
+   apm_pkg_ver__installed_p boolean,        -- default 'f'
+   apm_pkg_ver__data_model_loaded_p boolean -- default 'f'
+
+) RETURNS integer AS $$
+DECLARE
       v_version_id                      apm_package_versions.version_id%TYPE;
-begin
+BEGIN
       if apm_pkg_ver__version_id is null then
-         select nextval(''t_acs_object_id_seq'')
+         select nextval('t_acs_object_id_seq')
 	 into v_version_id
 	 from dual;
       else
@@ -1929,13 +2256,13 @@
 
       v_version_id := acs_object__new(
 		v_version_id,
-		''apm_package_version'',
+		'apm_package_version',
                 now(),
                 null,
                 null,
                 null,
-                ''t'',
-                apm_pkg_ver__package_key || '', Version '' || apm_pkg_ver__version_name,
+                't',
+                apm_pkg_ver__package_key || ', Version ' || apm_pkg_ver__version_name,
                 null
         );
 
@@ -1951,15 +2278,24 @@
 
       return v_version_id;		
   
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 
 -- procedure delete
-create or replace function apm_package_version__delete (integer)
-returns integer as '
-declare
-  delete__version_id             alias for $1;  
-begin
+
+
+-- added
+select define_function_args('apm_package_version__delete','version_id');
+
+--
+-- procedure apm_package_version__delete/1
+--
+CREATE OR REPLACE FUNCTION apm_package_version__delete(
+   delete__version_id integer
+) RETURNS integer AS $$
+DECLARE
+BEGIN
       delete from apm_package_owners 
       where version_id = delete__version_id; 
 
@@ -1972,50 +2308,78 @@
       PERFORM acs_object__delete(delete__version_id);
 
       return 0; 
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 
 -- procedure enable
-create or replace function apm_package_version__enable (integer)
-returns integer as '
-declare
-  enable__version_id             alias for $1;  
-begin
-      update apm_package_versions set enabled_p = ''t''
+
+
+-- added
+select define_function_args('apm_package_version__enable','version_id');
+
+--
+-- procedure apm_package_version__enable/1
+--
+CREATE OR REPLACE FUNCTION apm_package_version__enable(
+   enable__version_id integer
+) RETURNS integer AS $$
+DECLARE
+BEGIN
+      update apm_package_versions set enabled_p = 't'
       where version_id = enable__version_id;	
 
       return 0; 
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 
 -- procedure disable
-create or replace function apm_package_version__disable (integer)
-returns integer as '
-declare
-  disable__version_id             alias for $1;  
-begin
+
+
+-- added
+select define_function_args('apm_package_version__disable','version_id');
+
+--
+-- procedure apm_package_version__disable/1
+--
+CREATE OR REPLACE FUNCTION apm_package_version__disable(
+   disable__version_id integer
+) RETURNS integer AS $$
+DECLARE
+BEGIN
       update apm_package_versions 
-      set enabled_p = ''f''
+      set enabled_p = 'f'
       where version_id = disable__version_id;	
 
       return 0; 
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 
 -- function copy
-create or replace function apm_package_version__copy (integer,integer,varchar,varchar,boolean)
-returns integer as '
-declare
-  copy__version_id             alias for $1;  
-  copy__new_version_id         alias for $2;  -- default null  
-  copy__new_version_name       alias for $3;  
-  copy__new_version_uri        alias for $4;  
-  copy__copy_owners_p          alias for $5;
+
+
+-- added
+select define_function_args('apm_package_version__copy','version_id,new_version_id;null,new_version_name,new_version_uri,copy_owners_p');
+
+--
+-- procedure apm_package_version__copy/5
+--
+CREATE OR REPLACE FUNCTION apm_package_version__copy(
+   copy__version_id integer,
+   copy__new_version_id integer, -- default null
+   copy__new_version_name varchar,
+   copy__new_version_uri varchar,
+   copy__copy_owners_p boolean
+
+) RETURNS integer AS $$
+DECLARE
   v_version_id                 integer;       
-begin
+BEGIN
 	v_version_id := acs_object__new(
 		copy__new_version_id,
-		''apm_package_version'',
+		'apm_package_version',
                 now(),
                 null,
                 null,
@@ -2032,13 +2396,13 @@
 	    where version_id = copy__version_id;
     
         update acs_objects
-        set title = (select v.package_key || '', Version '' || v.version_name
+        set title = (select v.package_key || ', Version ' || v.version_name
                      from apm_package_versions v
                      where v.version_id = copy__version_id)
         where object_id = copy__version_id;
 
 	insert into apm_package_dependencies(dependency_id, version_id, dependency_type, service_uri, service_version)
-	    select nextval(''t_acs_object_id_seq''), v_version_id, dependency_type, service_uri, service_version
+	    select nextval('t_acs_object_id_seq'), v_version_id, dependency_type, service_uri, service_version
 	    from apm_package_dependencies
 	    where version_id = copy__version_id;
     
@@ -2056,29 +2420,39 @@
     
 	return v_version_id;
    
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 
 -- function edit
-create or replace function apm_package_version__edit (integer,integer,varchar,varchar,varchar,varchar,varchar,timestamptz,varchar,varchar,varchar,boolean,boolean)
-returns integer as '
-declare
-  edit__new_version_id         alias for $1;  -- default null  
-  edit__version_id             alias for $2;  
-  edit__version_name           alias for $3;  -- default null
-  edit__version_uri            alias for $4;  
-  edit__summary                alias for $5;  
-  edit__description_format     alias for $6;  
-  edit__description            alias for $7;  
-  edit__release_date           alias for $8;  
-  edit__vendor                 alias for $9;  
-  edit__vendor_uri             alias for $10; 
-  edit__auto_mount             alias for $11;
-  edit__installed_p            alias for $12; -- default ''f''
-  edit__data_model_loaded_p    alias for $13; -- default ''f''
+
+
+-- added
+select define_function_args('apm_package_version__edit','new_version_id;null,version_id,version_name;null,version_uri,summary,description_format,description,release_date,vendor,vendor_uri,auto_mount,installed_p;f,data_model_loaded_p;f');
+
+--
+-- procedure apm_package_version__edit/13
+--
+CREATE OR REPLACE FUNCTION apm_package_version__edit(
+   edit__new_version_id integer,     -- default null
+   edit__version_id integer,
+   edit__version_name varchar,       -- default null
+   edit__version_uri varchar,
+   edit__summary varchar,
+   edit__description_format varchar,
+   edit__description varchar,
+   edit__release_date timestamptz,
+   edit__vendor varchar,
+   edit__vendor_uri varchar,
+   edit__auto_mount varchar,
+   edit__installed_p boolean,        -- default 'f'
+   edit__data_model_loaded_p boolean -- default 'f'
+
+) RETURNS integer AS $$
+DECLARE
   v_version_id                 apm_package_versions.version_id%TYPE;
   version_unchanged_p          integer;       
-begin
+BEGIN
        -- Determine if version has changed.
        select case when count(*) = 0 then 0 else 1 end into version_unchanged_p
        from apm_package_versions
@@ -2090,7 +2464,7 @@
 			 edit__new_version_id,
 			 edit__version_name,
 			 edit__version_uri,
-                         ''f''
+                         'f'
 			);
          else 
 	   v_version_id := edit__version_id;			
@@ -2101,7 +2475,7 @@
 		summary = edit__summary,
 		description_format = edit__description_format,
 		description = edit__description,
-		release_date = date_trunc(''days'',now()),
+		release_date = date_trunc('days',now()),
 		vendor = edit__vendor,
 		vendor_uri = edit__vendor_uri,
                 auto_mount = edit__auto_mount,
@@ -2111,79 +2485,116 @@
 
 	return v_version_id;
      
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 -- function add_interface
-create or replace function apm_package_version__add_interface (integer,integer,varchar,varchar)
-returns integer as '
-declare
-  add_interface__interface_id         alias for $1;  -- default null  
-  add_interface__version_id           alias for $2;  
-  add_interface__interface_uri        alias for $3;  
-  add_interface__interface_version    alias for $4;  
+
+
+-- added
+select define_function_args('apm_package_version__add_interface','interface_id;null,version_id,interface_uri,interface_version');
+
+--
+-- procedure apm_package_version__add_interface/4
+--
+CREATE OR REPLACE FUNCTION apm_package_version__add_interface(
+   add_interface__interface_id integer, -- default null
+   add_interface__version_id integer,
+   add_interface__interface_uri varchar,
+   add_interface__interface_version varchar
+
+) RETURNS integer AS $$
+DECLARE
   v_dep_id                            apm_package_dependencies.dependency_id%TYPE;
-begin
+BEGIN
       if add_interface__interface_id is null then
-          select nextval(''t_acs_object_id_seq'') into v_dep_id from dual;
+          select nextval('t_acs_object_id_seq') into v_dep_id from dual;
       else
           v_dep_id := add_interface__interface_id;
       end if;
   
       insert into apm_package_dependencies
       (dependency_id, version_id, dependency_type, service_uri, service_version)
       values
-      (v_dep_id, add_interface__version_id, ''provides'', add_interface__interface_uri,
+      (v_dep_id, add_interface__version_id, 'provides', add_interface__interface_uri,
 	add_interface__interface_version);
 
       return v_dep_id;
    
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 
 -- procedure remove_interface
-create or replace function apm_package_version__remove_interface (integer)
-returns integer as '
-declare
-  remove_interface__interface_id           alias for $1;  
-begin
+
+
+-- added
+
+--
+-- procedure apm_package_version__remove_interface/1
+--
+CREATE OR REPLACE FUNCTION apm_package_version__remove_interface(
+   remove_interface__interface_id integer
+) RETURNS integer AS $$
+DECLARE
+BEGIN
     delete from apm_package_dependencies 
     where dependency_id = remove_interface__interface_id;
 
     return 0; 
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 
 -- procedure remove_interface
-create or replace function apm_package_version__remove_interface (varchar,varchar,integer)
-returns integer as '
-declare
-  remove_interface__interface_uri          alias for $1;  
-  remove_interface__interface_version      alias for $2;  
-  remove_interface__version_id             alias for $3;  
+
+
+-- added
+select define_function_args('apm_package_version__remove_interface','interface_uri,interface_version,version_id');
+
+--
+-- procedure apm_package_version__remove_interface/3
+--
+CREATE OR REPLACE FUNCTION apm_package_version__remove_interface(
+   remove_interface__interface_uri varchar,
+   remove_interface__interface_version varchar,
+   remove_interface__version_id integer
+) RETURNS integer AS $$
+DECLARE
   v_dep_id                           apm_package_dependencies.dependency_id%TYPE;
-begin
+BEGIN
       select dependency_id into v_dep_id from apm_package_dependencies
       where service_uri = remove_interface__interface_uri 
       and interface_version = remove_interface__interface_version;
       PERFORM apm_package_version__remove_interface(v_dep_id);
 
       return 0; 
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 
 -- function add_dependency
-create or replace function apm_package_version__add_dependency (varchar,integer,integer,varchar,varchar)
-returns integer as '
-declare
-  add_dependency__dependency_type        alias for $1;
-  add_dependency__dependency_id          alias for $2;  -- default null  
-  add_dependency__version_id             alias for $3;  
-  add_dependency__dependency_uri         alias for $4;  
-  add_dependency__dependency_version     alias for $5;  
+
+
+-- added
+select define_function_args('apm_package_version__add_dependency','dependency_type,dependency_id;null,version_id,dependency_uri,dependency_version');
+
+--
+-- procedure apm_package_version__add_dependency/5
+--
+CREATE OR REPLACE FUNCTION apm_package_version__add_dependency(
+   add_dependency__dependency_type varchar,
+   add_dependency__dependency_id integer, -- default null
+   add_dependency__version_id integer,
+   add_dependency__dependency_uri varchar,
+   add_dependency__dependency_version varchar
+
+) RETURNS integer AS $$
+DECLARE
   v_dep_id                            apm_package_dependencies.dependency_id%TYPE;
-begin
+BEGIN
       if add_dependency__dependency_id is null then
-          select nextval(''t_acs_object_id_seq'') into v_dep_id from dual;
+          select nextval('t_acs_object_id_seq') into v_dep_id from dual;
       else
           v_dep_id := add_dependency__dependency_id;
       end if;
@@ -2196,124 +2607,159 @@
 
       return v_dep_id;
    
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 
 -- procedure remove_dependency
-create or replace function apm_package_version__remove_dependency (integer)
-returns integer as '
-declare
-  remove_dependency__dependency_id          alias for $1;  
-begin
+
+
+-- added
+
+--
+-- procedure apm_package_version__remove_dependency/1
+--
+CREATE OR REPLACE FUNCTION apm_package_version__remove_dependency(
+   remove_dependency__dependency_id integer
+) RETURNS integer AS $$
+DECLARE
+BEGIN
     delete from apm_package_dependencies 
     where dependency_id = remove_dependency__dependency_id;
 
     return 0; 
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 
 -- procedure remove_dependency
-create or replace function apm_package_version__remove_dependency (varchar,varchar,integer)
-returns integer as '
-declare
-  remove_dependency__dependency_uri         alias for $1;  
-  remove_dependency__dependency_version     alias for $2;  
-  remove_dependency__version_id             alias for $3;  
+
+
+-- added
+select define_function_args('apm_package_version__remove_dependency','dependency_uri,dependency_version,version_id');
+
+--
+-- procedure apm_package_version__remove_dependency/3
+--
+CREATE OR REPLACE FUNCTION apm_package_version__remove_dependency(
+   remove_dependency__dependency_uri varchar,
+   remove_dependency__dependency_version varchar,
+   remove_dependency__version_id integer
+) RETURNS integer AS $$
+DECLARE
   v_dep_id                           apm_package_dependencies.dependency_id%TYPE;
-begin
+BEGIN
       select dependency_id into v_dep_id from apm_package_dependencies 
       where service_uri = remove_dependency__dependency_uri 
       and service_version = remove_dependency__dependency_version;
       PERFORM apm_package_version__remove_dependency(v_dep_id);
 
       return 0; 
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 
 -- function sortable_version_name
-create or replace function apm_package_version__sortable_version_name (varchar)
-returns varchar as '
-declare
-  version_name           alias for $1;  
+
+
+-- added
+select define_function_args('apm_package_version__sortable_version_name','version_name');
+
+--
+-- procedure apm_package_version__sortable_version_name/1
+--
+CREATE OR REPLACE FUNCTION apm_package_version__sortable_version_name(
+   version_name varchar
+) RETURNS varchar AS $$
+DECLARE
   a_fields               integer;       
   a_start                integer;       
   a_end                  integer;       
-  a_order                varchar(1000) default ''''; 
+  a_order                varchar(1000) default ''; 
   a_char                 char(1);       
-  a_seen_letter          boolean default ''f'';        
-begin
+  a_seen_letter          boolean default 'f';        
+BEGIN
         a_fields := 0;
 	a_start := 1;
 	loop
 	    a_end := a_start;
     
 	    -- keep incrementing a_end until we run into a non-number        
-	    while substr(version_name, a_end, 1) >= ''0'' and substr(version_name, a_end, 1) <= ''9'' loop
+	    while substr(version_name, a_end, 1) >= '0' and substr(version_name, a_end, 1) <= '9' loop
 		a_end := a_end + 1;
 	    end loop;
 	    if a_end = a_start then
 	    	return -1;
-		-- raise_application_error(-20000, ''Expected number at position '' || a_start);
+		-- raise_application_error(-20000, 'Expected number at position ' || a_start);
 	    end if;
 	    if a_end - a_start > 4 then
 	    	return -1;
-		-- raise_application_error(-20000, ''Numbers within versions can only be up to 4 digits long'');
+		-- raise_application_error(-20000, 'Numbers within versions can only be up to 4 digits long');
 	    end if;
     
 	    -- zero-pad and append the number
-	    a_order := a_order || substr(''0000'', 1, 4 - (a_end - a_start)) ||
-		substr(version_name, a_start, a_end - a_start) || ''.'';
+	    a_order := a_order || substr('0000', 1, 4 - (a_end - a_start)) ||
+		substr(version_name, a_start, a_end - a_start) || '.';
             a_fields := a_fields + 1;                                
 	    if a_end > length(version_name) then
-		-- end of string - we''re outta here
-		if a_seen_letter = ''f'' then
-		    -- append the "final" suffix if there haven''t been any letters
+		-- end of string - we're outta here
+		if a_seen_letter = 'f' then
+		    -- append the "final" suffix if there haven't been any letters
 		    -- so far (i.e., not development/alpha/beta)
-		    a_order := a_order || repeat(''0000.'',7 - a_fields) || ''  3F.'';
+		    a_order := a_order || repeat('0000.',7 - a_fields) || '  3F.';
 		end if;
 		return a_order;
 	    end if;
     
-	    -- what''s the next character? if a period, just skip it
+	    -- what's the next character? if a period, just skip it
 	    a_char := substr(version_name, a_end, 1);
-	    if a_char = ''.'' then
+	    if a_char = '.' then
 	    else
 		-- if the next character was a letter, append the appropriate characters
-		if a_char = ''d'' then
-		    a_order := a_order || repeat(''0000.'',7 - a_fields) || ''  0D.'';
-		else if a_char = ''a'' then
-		    a_order := a_order || repeat(''0000.'',7 - a_fields) || ''  1A.'';
-		else if a_char = ''b'' then
-		    a_order := a_order || repeat(''0000.'',7 - a_fields) || ''  2B.'';
+		if a_char = 'd' then
+		    a_order := a_order || repeat('0000.',7 - a_fields) || '  0D.';
+		else if a_char = 'a' then
+		    a_order := a_order || repeat('0000.',7 - a_fields) || '  1A.';
+		else if a_char = 'b' then
+		    a_order := a_order || repeat('0000.',7 - a_fields) || '  2B.';
 		end if; end if; end if;
     
-		-- can''t have something like 3.3a1b2 - just one letter allowed!
-		if a_seen_letter = ''t'' then
+		-- can't have something like 3.3a1b2 - just one letter allowed!
+		if a_seen_letter = 't' then
 		    return -1;
-		    -- raise_application_error(-20000, ''Not allowed to have two letters in version name ''''''
-		    --	|| version_name || '''''''');
+		    -- raise_application_error(-20000, 'Not allowed to have two letters in version name '''
+		    --	|| version_name || '''');
 		end if;
-		a_seen_letter := ''t'';
+		a_seen_letter := 't';
     
-		-- end of string - we''re done!
+		-- end of string - we're done!
 		if a_end = length(version_name) then
 		    return a_order;
 		end if;
 	    end if;
 	    a_start := a_end + 1;
 	end loop;
     
-end;' language 'plpgsql' immutable;
+END;
+$$ LANGUAGE plpgsql immutable;
 
 -- function version_name_greater
-create or replace function apm_package_version__version_name_greater (varchar,varchar)
-returns integer as '
-declare
-  version_name_one       alias for $1;  
-  version_name_two       alias for $2;
+
+
+-- added
+select define_function_args('apm_package_version__version_name_greater','version_name_one,version_name_two');
+
+--
+-- procedure apm_package_version__version_name_greater/2
+--
+CREATE OR REPLACE FUNCTION apm_package_version__version_name_greater(
+   version_name_one varchar,
+   version_name_two varchar
+) RETURNS integer AS $$
+DECLARE
   a_order_a		 varchar(250);
   a_order_b		 varchar(250);  
-begin
+BEGIN
 	a_order_a := apm_package_version__sortable_version_name(version_name_one);
 	a_order_b := apm_package_version__sortable_version_name(version_name_two);
 	if a_order_a < a_order_b then
@@ -2323,37 +2769,46 @@
 	end if; end if;
 
 	return 0;   
-end;' language 'plpgsql' immutable;
+END;
+$$ LANGUAGE plpgsql immutable;
 
 -- function upgrade_p
-create or replace function apm_package_version__upgrade_p (varchar,varchar,varchar)
-returns integer as '
-declare
-  upgrade_p__path                   alias for $1;  
-  upgrade_p__initial_version_name   alias for $2;  
-  upgrade_p__final_version_name     alias for $3;  
+
+
+-- added
+select define_function_args('apm_package_version__upgrade_p','path,initial_version_name,final_version_name');
+
+--
+-- procedure apm_package_version__upgrade_p/3
+--
+CREATE OR REPLACE FUNCTION apm_package_version__upgrade_p(
+   upgrade_p__path varchar,
+   upgrade_p__initial_version_name varchar,
+   upgrade_p__final_version_name varchar
+) RETURNS integer AS $$
+DECLARE
   v_pos1                            integer;       
   v_pos2                            integer;       
   v_tmp                             varchar(1500);
   v_path                            varchar(1500);
   v_version_from                    apm_package_versions.version_name%TYPE;
   v_version_to                      apm_package_versions.version_name%TYPE;
-begin
+BEGIN
 
 	-- Set v_path to the tail of the path (the file name).        
-	v_path := substr(upgrade_p__path, instr(upgrade_p__path, ''/'', -1) + 1);
+	v_path := substr(upgrade_p__path, instr(upgrade_p__path, '/', -1) + 1);
 
 	-- Remove the extension, if it is .sql.
-	v_pos1 := position(''.sql'' in v_path);
+	v_pos1 := position('.sql' in v_path);
 	if v_pos1 > 0 then
 	    v_path := substr(v_path, 1, v_pos1 - 1);
 	end if;
 
 	-- Figure out the from/to version numbers for the individual file.
-	v_pos1 := instr(v_path, ''-'', -1, 2);
-	v_pos2 := instr(v_path, ''-'', -1);
+	v_pos1 := instr(v_path, '-', -1, 2);
+	v_pos2 := instr(v_path, '-', -1);
 	if v_pos1 = 0 or v_pos2 = 0 then
-	    -- There aren''t two hyphens in the file name. Bail.
+	    -- There aren't two hyphens in the file name. Bail.
 	    return 0;
 	end if;
 
@@ -2370,49 +2825,68 @@
 	-- Invalid version number.
 	-- return 0;
    
-end;' language 'plpgsql' immutable;
+END;
+$$ LANGUAGE plpgsql immutable;
 
 
 -- procedure upgrade
-create or replace function apm_package_version__upgrade (integer)
-returns integer as '
-declare
-  upgrade__version_id             alias for $1;  
-begin
+
+
+-- added
+select define_function_args('apm_package_version__upgrade','version_id');
+
+--
+-- procedure apm_package_version__upgrade/1
+--
+CREATE OR REPLACE FUNCTION apm_package_version__upgrade(
+   upgrade__version_id integer
+) RETURNS integer AS $$
+DECLARE
+BEGIN
     update apm_package_versions
-    	set enabled_p = ''f'',
-	    installed_p = ''f''
+    	set enabled_p = 'f',
+	    installed_p = 'f'
 	where package_key = (select package_key from apm_package_versions
 	    	    	     where version_id = upgrade__version_id);
     update apm_package_versions
-    	set enabled_p = ''t'',
-	    installed_p = ''t''
+    	set enabled_p = 't',
+	    installed_p = 't'
 	where version_id = upgrade__version_id;			  
     
     return 0; 
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 
 
 -- show errors
 
 -- create or replace package body apm_package_type
 -- procedure create_type
-create or replace function apm_package_type__create_type (varchar,varchar,varchar,varchar,varchar,boolean,boolean,boolean,boolean,varchar,integer)
-returns integer as '
-declare
-  create_type__package_key            alias for $1;  
-  create_type__pretty_name            alias for $2;  
-  create_type__pretty_plural          alias for $3;  
-  create_type__package_uri            alias for $4;  
-  create_type__package_type           alias for $5;  
-  create_type__initial_install_p      alias for $6;  
-  create_type__singleton_p            alias for $7;  
-  create_type__implements_subsite_p   alias for $8;
-  create_type__inherit_templates_p    alias for $9;
-  create_type__spec_file_path         alias for $10;  -- default null  
-  create_type__spec_file_mtime        alias for $11;  -- default null
-begin
+
+
+-- added
+select define_function_args('apm_package_type__create_type','package_key,pretty_name,pretty_plural,package_uri,package_type,initial_install_p,singleton_p,implements_subsite_p,inherit_templates_p,spec_file_path;null,spec_file_mtime;null');
+
+--
+-- procedure apm_package_type__create_type/11
+--
+CREATE OR REPLACE FUNCTION apm_package_type__create_type(
+   create_type__package_key varchar,
+   create_type__pretty_name varchar,
+   create_type__pretty_plural varchar,
+   create_type__package_uri varchar,
+   create_type__package_type varchar,
+   create_type__initial_install_p boolean,
+   create_type__singleton_p boolean,
+   create_type__implements_subsite_p boolean,
+   create_type__inherit_templates_p boolean,
+   create_type__spec_file_path varchar, -- default null
+   create_type__spec_file_mtime integer -- default null
+
+) RETURNS integer AS $$
+DECLARE
+BEGIN
    insert into apm_package_types
     (package_key, pretty_name, pretty_plural, package_uri, package_type,
     spec_file_path, spec_file_mtime, initial_install_p, singleton_p,
@@ -2424,25 +2898,35 @@
      create_type__implements_subsite_p, create_type__inherit_templates_p);
 
    return 0; 
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 
 -- function update_type
-create or replace function apm_package_type__update_type (varchar,varchar,varchar,varchar,varchar,boolean,boolean,boolean,boolean,varchar,integer)
-returns varchar as '
-declare
-  update_type__package_key            alias for $1;  
-  update_type__pretty_name            alias for $2;  -- default null  
-  update_type__pretty_plural          alias for $3;  -- default null
-  update_type__package_uri            alias for $4;  -- default null
-  update_type__package_type           alias for $5;  -- default null  
-  update_type__initial_install_p      alias for $6;  -- default null  
-  update_type__singleton_p            alias for $7;  -- default null  
-  update_type__implements_subsite_p   alias for $8;  -- default null  
-  update_type__inherit_templates_p    alias for $9;  -- default null  
-  update_type__spec_file_path         alias for $10;  -- default null  
-  update_type__spec_file_mtime        alias for $11;  -- default null  
-begin
+
+
+-- added
+select define_function_args('apm_package_type__update_type','package_key,pretty_name;null,pretty_plural;null,package_uri;null,package_type;null,initial_install_p;null,singleton_p;null,implements_subsite_p;null,inherit_templates_p;null,spec_file_path;null,spec_file_mtime;null');
+
+--
+-- procedure apm_package_type__update_type/11
+--
+CREATE OR REPLACE FUNCTION apm_package_type__update_type(
+   update_type__package_key varchar,
+   update_type__pretty_name varchar,          -- default null
+   update_type__pretty_plural varchar,        -- default null
+   update_type__package_uri varchar,          -- default null
+   update_type__package_type varchar,         -- default null
+   update_type__initial_install_p boolean,    -- default null
+   update_type__singleton_p boolean,          -- default null
+   update_type__implements_subsite_p boolean, -- default null
+   update_type__inherit_templates_p boolean,  -- default null
+   update_type__spec_file_path varchar,       -- default null
+   update_type__spec_file_mtime integer       -- default null
+
+) RETURNS varchar AS $$
+DECLARE
+BEGIN
       UPDATE apm_package_types SET
       	pretty_name = coalesce(update_type__pretty_name, pretty_name),
     	pretty_plural = coalesce(update_type__pretty_plural, pretty_plural),
@@ -2458,18 +2942,28 @@
 
       return update_type__package_key;
    
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 
 -- procedure drop_type
-create or replace function apm_package_type__drop_type (varchar,boolean)
-returns integer as '
-declare
-  drop_type__package_key            alias for $1;  
-  drop_type__cascade_p              alias for $2;  -- default ''f''
+
+
+-- added
+select define_function_args('apm_package_type__drop_type','package_key,cascade_p;f');
+
+--
+-- procedure apm_package_type__drop_type/2
+--
+CREATE OR REPLACE FUNCTION apm_package_type__drop_type(
+   drop_type__package_key varchar,
+   drop_type__cascade_p boolean -- default 'f'
+
+) RETURNS integer AS $$
+DECLARE
   cur_val                           record; 
-begin
-    if drop_type__cascade_p = ''t'' then
+BEGIN
+    if drop_type__cascade_p = 't' then
         for cur_val in select package_id
        from apm_packages
        where package_key = drop_type__package_key
@@ -2496,23 +2990,33 @@
     where package_key = drop_type__package_key;
 
     return 0; 
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 
 -- function num_parameters
-create or replace function apm_package_type__num_parameters (varchar)
-returns integer as '
-declare
-  num_parameters__package_key            alias for $1;  
+
+
+-- added
+select define_function_args('apm_package_type__num_parameters','package_key');
+
+--
+-- procedure apm_package_type__num_parameters/1
+--
+CREATE OR REPLACE FUNCTION apm_package_type__num_parameters(
+   num_parameters__package_key varchar
+) RETURNS integer AS $$
+DECLARE
   v_count                                integer;       
-begin
+BEGIN
     select count(*) into v_count
     from apm_parameters
     where package_key = num_parameters__package_key;
 
     return v_count;
    
-end;' language 'plpgsql' stable;
+END;
+$$ LANGUAGE plpgsql stable;
 
 
 
@@ -2522,26 +3026,35 @@
 
 -- create or replace package body apm_parameter_value
 -- function new
-create or replace function apm_parameter_value__new (integer,integer,integer,varchar)
-returns integer as '
-declare
-  new__value_id               alias for $1;  -- default null  
-  new__package_id             alias for $2;  
-  new__parameter_id           alias for $3;  
-  new__attr_value             alias for $4;  
+
+
+-- added
+select define_function_args('apm_parameter_value__new','value_id;null,package_id,parameter_id,attr_value');
+
+--
+-- procedure apm_parameter_value__new/4
+--
+CREATE OR REPLACE FUNCTION apm_parameter_value__new(
+   new__value_id integer, -- default null
+   new__package_id integer,
+   new__parameter_id integer,
+   new__attr_value varchar
+
+) RETURNS integer AS $$
+DECLARE
   v_value_id                  apm_parameter_values.value_id%TYPE;
   v_title                     acs_objects.title%TYPE;
-begin
-   select pkg.package_key || '': '' || pkg.instance_name || '' - '' || par.parameter_name into v_title from apm_packages pkg, apm_parameters par where pkg.package_id = new__package_id and par.parameter_id = new__parameter_id;
+BEGIN
+   select pkg.package_key || ': ' || pkg.instance_name || ' - ' || par.parameter_name into v_title from apm_packages pkg, apm_parameters par where pkg.package_id = new__package_id and par.parameter_id = new__parameter_id;
 
    v_value_id := acs_object__new(
      new__value_id,
-     ''apm_parameter_value'',
+     'apm_parameter_value',
      now(),
      null,
      null,
      null,
-     ''t'',
+     't',
      v_title,
      new__package_id
    );
@@ -2553,37 +3066,57 @@
 
    return v_value_id;
 
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 
 -- procedure delete
-create or replace function apm_parameter_value__delete (integer)
-returns integer as '
-declare
-  delete__value_id               alias for $1;  -- default null
-begin
+
+
+-- added
+select define_function_args('apm_parameter_value__delete','value_id;null');
+
+--
+-- procedure apm_parameter_value__delete/1
+--
+CREATE OR REPLACE FUNCTION apm_parameter_value__delete(
+   delete__value_id integer -- default null
+
+) RETURNS integer AS $$
+DECLARE
+BEGIN
     delete from apm_parameter_values 
     where value_id = delete__value_id;
     PERFORM acs_object__delete(delete__value_id);
 
     return 0; 
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 
 -- function new
-create or replace function apm_application__new (integer,varchar,varchar,varchar,timestamptz,integer,varchar,integer)
-returns integer as '
-declare
-  application_id         alias for $1;  -- default null  
-  instance_name          alias for $2;  -- default null
-  package_key            alias for $3;  
-  object_type            alias for $4;  -- default ''apm_application''
-  creation_date          alias for $5;  -- default now()
-  creation_user          alias for $6;  -- default null
-  creation_ip            alias for $7;  -- default null
-  context_id             alias for $8;  -- default null
+
+
+-- added
+select define_function_args('apm_application__new','application_id;null,instance_name;null,package_key,object_type;apm_application,creation_date;now(),creation_user;null,creation_ip;null,context_id;null');
+
+--
+-- procedure apm_application__new/8
+--
+CREATE OR REPLACE FUNCTION apm_application__new(
+   application_id integer,    -- default null
+   instance_name varchar,     -- default null
+   package_key varchar,
+   object_type varchar,       -- default 'apm_application'
+   creation_date timestamptz, -- default now()
+   creation_user integer,     -- default null
+   creation_ip varchar,       -- default null
+   context_id integer         -- default null
+
+) RETURNS integer AS $$
+DECLARE
   v_application_id       integer;       
-begin
+BEGIN
     v_application_id := apm_package__new (
       application_id,
       instance_name,
@@ -2597,43 +3130,62 @@
 
     return v_application_id;
    
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 
 -- procedure delete
-create or replace function apm_application__delete (integer)
-returns integer as '
-declare
-  delete__application_id         alias for $1;  
-begin
+
+
+-- added
+select define_function_args('apm_application__delete','application_id');
+
+--
+-- procedure apm_application__delete/1
+--
+CREATE OR REPLACE FUNCTION apm_application__delete(
+   delete__application_id integer
+) RETURNS integer AS $$
+DECLARE
+BEGIN
     delete from apm_applications
     where application_id = delete__application_id;
     PERFORM apm_package__delete(
         delete__application_id
     );
 
     return 0; 
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 
 
 -- show errors
 
 -- create or replace package body apm_service
 -- function new
-create or replace function apm_service__new (integer,varchar,varchar,varchar,timestamptz,integer,varchar,integer)
-returns integer as '
-declare
-  service_id             alias for $1;  -- default null  
-  instance_name          alias for $2;  -- default null
-  package_key            alias for $3;  
-  object_type            alias for $4;  -- default ''apm_service''
-  creation_date          alias for $5;  -- default now()
-  creation_user          alias for $6;  -- default null
-  creation_ip            alias for $7;  -- default null
-  context_id             alias for $8;  -- default null
+
+
+-- added
+select define_function_args('apm_service__new','service_id;null,instance_name;null,package_key,object_type;apm_service,creation_date;now(),creation_user;null,creation_ip;null,context_id;null');
+
+--
+-- procedure apm_service__new/8
+--
+CREATE OR REPLACE FUNCTION apm_service__new(
+   service_id integer,        -- default null
+   instance_name varchar,     -- default null
+   package_key varchar,
+   object_type varchar,       -- default 'apm_service'
+   creation_date timestamptz, -- default now()
+   creation_user integer,     -- default null
+   creation_ip varchar,       -- default null
+   context_id integer         -- default null
+
+) RETURNS integer AS $$
+DECLARE
   v_service_id           integer;       
-begin
+BEGIN
     v_service_id := apm_package__new (
       service_id,
       instance_name,
@@ -2647,21 +3199,31 @@
 
     return v_service_id;
    
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 
 -- procedure delete
-create or replace function apm_service__delete (integer)
-returns integer as '
-declare
-  delete__service_id    alias for $1;  
-begin
+
+
+-- added
+select define_function_args('apm_service__delete','service_id');
+
+--
+-- procedure apm_service__delete/1
+--
+CREATE OR REPLACE FUNCTION apm_service__delete(
+   delete__service_id integer
+) RETURNS integer AS $$
+DECLARE
+BEGIN
     delete from apm_services
     where service_id = delete__service_id;
     PERFORM apm_package__delete(
 	delete__service_id
     );
 
     return 0; 
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
