Index: openacs-4/packages/acs-service-contract/sql/postgresql/acs-sc-packages-create.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-service-contract/sql/postgresql/acs-sc-packages-create.sql,v
diff -u -r1.7 -r1.8
--- openacs-4/packages/acs-service-contract/sql/postgresql/acs-sc-packages-create.sql	11 Sep 2003 08:27:24 -0000	1.7
+++ openacs-4/packages/acs-service-contract/sql/postgresql/acs-sc-packages-create.sql	11 Sep 2003 09:12:17 -0000	1.8
@@ -1,9 +1,9 @@
 create function acs_sc_contract__new(varchar,text)
 returns integer as '
 declare
-    p_contract_name		alias for $1;
-    p_contract_desc		alias for $2;
-    v_contract_id		integer;
+    p_contract_name             alias for $1;
+    p_contract_desc             alias for $2;
+    v_contract_id               integer;
 begin
 
     v_contract_id := acs_object__new(
@@ -51,8 +51,8 @@
 create function acs_sc_contract__get_name(integer)
 returns varchar as '
 declare
-    p_contract_id		alias for $1;
-    v_contract_name		varchar;
+    p_contract_id               alias for $1;
+    v_contract_name             varchar;
 begin
 
     select contract_name into v_contract_name
@@ -68,7 +68,7 @@
 create function acs_sc_contract__delete(integer)
 returns integer as '
 declare
-    p_contract_id		alias for $1;
+    p_contract_id               alias for $1;
 begin
 
     delete from acs_sc_contracts
@@ -83,8 +83,8 @@
 create function acs_sc_contract__delete(varchar)
 returns integer as '
 declare
-    p_contract_name		alias for $1;
-    v_contract_id		integer;
+    p_contract_name             alias for $1;
+    v_contract_id               integer;
 begin
 
     v_contract_id := acs_sc_contract__get_id(p_contract_name);
@@ -100,17 +100,17 @@
 create function acs_sc_operation__new(varchar,varchar,text,boolean,integer,varchar,varchar)
 returns integer as '
 declare
-    p_contract_name		alias for $1;
+    p_contract_name             alias for $1;
     p_operation_name            alias for $2;
-    p_operation_desc		alias for $3;
-    p_operation_iscachable_p	alias for $4;
-    p_operation_nargs		alias for $5;
-    p_operation_inputtype	alias for $6;
-    p_operation_outputtype	alias for $7;
+    p_operation_desc            alias for $3;
+    p_operation_iscachable_p    alias for $4;
+    p_operation_nargs           alias for $5;
+    p_operation_inputtype       alias for $6;
+    p_operation_outputtype      alias for $7;
     v_contract_id               integer;
-    v_operation_id		integer;
-    v_operation_inputtype_id	integer;
-    v_operation_outputtype_id	integer;
+    v_operation_id              integer;
+    v_operation_inputtype_id    integer;
+    v_operation_outputtype_id   integer;
 begin
 
     v_contract_id := acs_sc_contract__get_id(p_contract_name);
@@ -131,23 +131,23 @@
     insert into acs_sc_operations (
         contract_id,
         operation_id,
-	contract_name,
-	operation_name,
-	operation_desc,
-	operation_iscachable_p,
-	operation_nargs,
-	operation_inputtype_id,
-	operation_outputtype_id
+        contract_name,
+        operation_name,
+        operation_desc,
+        operation_iscachable_p,
+        operation_nargs,
+        operation_inputtype_id,
+        operation_outputtype_id
     ) values (
         v_contract_id,
         v_operation_id,
-	p_contract_name,
-	p_operation_name,
-	p_operation_desc,
-	p_operation_iscachable_p,
-	p_operation_nargs,
-	v_operation_inputtype_id,
-	v_operation_outputtype_id
+        p_contract_name,
+        p_operation_name,
+        p_operation_desc,
+        p_operation_iscachable_p,
+        p_operation_nargs,
+        v_operation_inputtype_id,
+        v_operation_outputtype_id
     );
 
     return v_operation_id;
@@ -159,7 +159,7 @@
 create function acs_sc_operation__get_id(varchar,varchar)
 returns integer as '
 declare
-    p_contract_name		alias for $1;
+    p_contract_name             alias for $1;
     p_operation_name            alias for $2;
     v_operation_id               integer;
 begin
@@ -178,7 +178,7 @@
 create function acs_sc_operation__delete(integer)
 returns integer as '
 declare
-    p_operation_id		alias for $1;
+    p_operation_id              alias for $1;
 begin
 
     delete from acs_sc_operations
@@ -193,15 +193,15 @@
 create function acs_sc_operation__delete(varchar,varchar)
 returns integer as '
 declare
-    p_contract_name		alias for $1;
-    p_operation_name		alias for $2;
-    v_operation_id		integer;
+    p_contract_name             alias for $1;
+    p_operation_name            alias for $2;
+    v_operation_id              integer;
 begin
 
     v_operation_id := acs_sc_operation__get_id(
-		          p_contract_name,
-			  p_operation_name
-		      );
+                          p_contract_name,
+                          p_operation_name
+                      );
 
     perform acs_sc_operation__delete(v_operation_id);
 
@@ -212,11 +212,11 @@
 create function acs_sc_impl__new(varchar,varchar,varchar,varchar)
 returns integer as '
 declare
-    p_impl_contract_name	alias for $1;
-    p_impl_name			alias for $2;
+    p_impl_contract_name        alias for $1;
+    p_impl_name                 alias for $2;
     p_impl_pretty_name          alias for $3;
-    p_impl_owner_name		alias for $4;
-    v_impl_id			integer;
+    p_impl_owner_name           alias for $4;
+    v_impl_id                   integer;
 begin
 
     v_impl_id := acs_object__new(
@@ -230,46 +230,49 @@
 
     insert into acs_sc_impls (
         impl_id,
-	impl_name,
+        impl_name,
         impl_pretty_name,
         impl_owner_name,
-	impl_contract_name
+        impl_contract_name
     ) values (
         v_impl_id,
-	p_impl_name,
+        p_impl_name,
         p_impl_pretty_name,
-	p_impl_owner_name,
-	p_impl_contract_name
+        p_impl_owner_name,
+        p_impl_contract_name
     );
 
     return v_impl_id;
 
 end;' language 'plpgsql';
 
 -- Only three arguments, defaults pretty name to empty string
-create function acs_sc_impl__new(varchar,varchar,varchar)
+create or replace function acs_sc_impl__new(varchar,varchar,varchar)
 returns integer as '
 declare
-    p_impl_contract_name	alias for $1;
-    p_impl_name			alias for $2;
-    p_impl_owner_name		alias for $3;
-    v_impl_id			integer;
+    p_impl_contract_name        alias for $1;
+    p_impl_name                 alias for $2;
+    p_impl_owner_name           alias for $3;
+    v_impl_id                   integer;
 begin
     -- Using an empty pretty name
-    v_impl_id := acs_sc_impl__new(p_impl_contract_name,
-                                  p_impl_name,
-                                  '',
-                                  p_impl_owner_name);
+    v_impl_id := acs_sc_impl__new(
+        p_impl_contract_name,
+        p_impl_name,
+        null,
+        p_impl_owner_name
+    );
+
     return v_impl_id;
 
 end;' language 'plpgsql';
 
 create function acs_sc_impl__get_id(varchar,varchar)
 returns integer as '
 declare
-    p_impl_contract_name	alias for $1;
-    p_impl_name			alias for $2;
-    v_impl_id			integer;
+    p_impl_contract_name        alias for $1;
+    p_impl_name                 alias for $2;
+    v_impl_id                   integer;
 begin
 
     select impl_id into v_impl_id
@@ -285,8 +288,8 @@
 create function acs_sc_impl__get_name(integer)
 returns varchar as '
 declare
-    p_impl_id			alias for $1;
-    v_impl_name			varchar;
+    p_impl_id                   alias for $1;
+    v_impl_name                 varchar;
 begin
 
     select impl_name into v_impl_name
@@ -302,8 +305,8 @@
 create function acs_sc_impl__delete(varchar,varchar)
 returns integer as '
 declare
-    p_impl_contract_name	alias for $1;
-    p_impl_name			alias for $2;
+    p_impl_contract_name        alias for $1;
+    p_impl_name                 alias for $2;
 begin
 
     delete from acs_sc_impls
@@ -322,30 +325,30 @@
 create function acs_sc_impl_alias__new(varchar,varchar,varchar,varchar,varchar)
 returns integer as '
 declare
-    p_impl_contract_name	alias for $1;
-    p_impl_name			alias for $2;
-    p_impl_operation_name	alias for $3;
-    p_impl_alias		alias for $4;
-    p_impl_pl			alias for $5;
-    v_impl_id			integer;
+    p_impl_contract_name        alias for $1;
+    p_impl_name                 alias for $2;
+    p_impl_operation_name       alias for $3;
+    p_impl_alias                alias for $4;
+    p_impl_pl                   alias for $5;
+    v_impl_id                   integer;
 begin
 
     v_impl_id := acs_sc_impl__get_id(p_impl_contract_name,p_impl_name);
 
     insert into acs_sc_impl_aliases (
         impl_id,
-	impl_name,
-	impl_contract_name,
-	impl_operation_name,
-	impl_alias,
-	impl_pl
+        impl_name,
+        impl_contract_name,
+        impl_operation_name,
+        impl_alias,
+        impl_pl
     ) values (
         v_impl_id,
-	p_impl_name,
-	p_impl_contract_name,
-	p_impl_operation_name,
-	p_impl_alias,
-	p_impl_pl
+        p_impl_name,
+        p_impl_contract_name,
+        p_impl_operation_name,
+        p_impl_alias,
+        p_impl_pl
     );
 
     return v_impl_id;
@@ -358,10 +361,10 @@
 create function acs_sc_impl_alias__delete(varchar,varchar,varchar)
 returns integer as '
 declare
-    p_impl_contract_name	alias for $1;
-    p_impl_name			alias for $2;
-    p_impl_operation_name	alias for $3;
-    v_impl_id			integer;
+    p_impl_contract_name        alias for $1;
+    p_impl_name                 alias for $2;
+    p_impl_operation_name       alias for $3;
+    v_impl_id                   integer;
 begin
 
     v_impl_id := acs_sc_impl__get_id(p_impl_contract_name, p_impl_name);
@@ -380,11 +383,11 @@
 create function acs_sc_binding__new(integer,integer)
 returns integer as '
 declare
-    p_contract_id		alias for $1;
-    p_impl_id			alias for $2;
-    v_contract_name		varchar;
-    v_impl_name			varchar;
-    v_count			integer;
+    p_contract_id               alias for $1;
+    p_impl_id                   alias for $2;
+    v_contract_name             varchar;
+    v_impl_name                 varchar;
+    v_count                     integer;
 begin
 
     v_contract_name := acs_sc_contract__get_name(p_contract_id);
@@ -394,20 +397,20 @@
     from acs_sc_operations
     where contract_id = p_contract_id
     and operation_name not in (select impl_operation_name
-		       	       from acs_sc_impl_aliases
-			       where impl_contract_name = v_contract_name
-			       and impl_id = p_impl_id);
+                               from acs_sc_impl_aliases
+                               where impl_contract_name = v_contract_name
+                               and impl_id = p_impl_id);
 
     if v_count > 0 then
         raise exception ''Binding of % to % failed since certain operations are not implemented.'', v_contract_name, v_impl_name;
     end if;
 
     insert into acs_sc_bindings (
         contract_id,
-	impl_id
+        impl_id
     ) values (
         p_contract_id,
-	p_impl_id
+        p_impl_id
     );
 
     return 0;
@@ -419,11 +422,11 @@
 create function acs_sc_binding__new(varchar,varchar)
 returns integer as '
 declare
-    p_contract_name		alias for $1;
-    p_impl_name			alias for $2;
-    v_contract_id		integer;
-    v_impl_id			integer;
-    v_count			integer;
+    p_contract_name             alias for $1;
+    p_impl_name                 alias for $2;
+    v_contract_id               integer;
+    v_impl_id                   integer;
+    v_count                     integer;
 begin
 
     v_contract_id := acs_sc_contract__get_id(p_contract_name);
@@ -444,8 +447,8 @@
 create function acs_sc_binding__delete(integer,integer)
 returns integer as '
 declare
-    p_contract_id		alias for $1;
-    p_impl_id			alias for $2;
+    p_contract_id               alias for $1;
+    p_impl_id                   alias for $2;
 begin
 
     delete from acs_sc_bindings
@@ -459,10 +462,10 @@
 create function acs_sc_binding__delete(varchar,varchar)
 returns integer as '
 declare
-    p_contract_name		alias for $1;
-    p_impl_name			alias for $2;
-    v_contract_id		integer;
-    v_impl_id			integer;
+    p_contract_name             alias for $1;
+    p_impl_name                 alias for $2;
+    v_contract_id               integer;
+    v_impl_id                   integer;
 begin
 
     v_contract_id := acs_sc_contract__get_id(p_contract_name);
@@ -480,11 +483,11 @@
 create function acs_sc_binding__exists_p(varchar,varchar)
 returns integer as '
 declare
-    p_contract_name		alias for $1;
-    p_impl_name			alias for $2;
-    v_contract_id		integer;
-    v_impl_id			integer;
-    v_exists_p			integer;
+    p_contract_name             alias for $1;
+    p_impl_name                 alias for $2;
+    v_contract_id               integer;
+    v_impl_id                   integer;
+    v_exists_p                  integer;
 begin
 
     v_contract_id := acs_sc_contract__get_id(p_contract_name);