Index: openacs-4/packages/acs-kernel/sql/oracle/apm-create.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/oracle/apm-create.sql,v
diff -u -r1.52 -r1.53
--- openacs-4/packages/acs-kernel/sql/oracle/apm-create.sql	31 Mar 2010 00:46:16 -0000	1.52
+++ openacs-4/packages/acs-kernel/sql/oracle/apm-create.sql	31 Mar 2010 01:21:00 -0000	1.53
@@ -1098,6 +1098,11 @@
         package_id in apm_packages.package_id%TYPE
     ) return apm_packages.package_id%TYPE;
 
+  function is_child (
+    parent_package_key in apm_packages.package_key%TYPE,
+    child_package_key in apm_packages.package_key%TYPE
+  ) return char;
+
 end apm_package;
 /
 show errors
@@ -2055,6 +2060,35 @@
             return -1;
     end parent_id;
 
+  function is_child (
+    parent_package_key in apm_packages.package_key%TYPE,
+    child_package_key in apm_packages.package_key%TYPE
+  ) return char
+    is
+    begin
+
+      if parent_package_key = child_package_key then
+        return 't';
+      end if;
+
+      for row 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 = 't'
+           and apd.dependency_type in ('embeds', 'extends')
+           and apv.package_key = child_package_key)
+      loop
+        if row.service_uri = parent_package_key or
+          is_child(parent_package_key, row.service_uri) = 't' then
+        return 't';
+      end if;
+    end loop;
+ 
+    return 'f';
+  end is_child;
+
+
 end apm_package;
 /
 show errors
