Index: openacs.org-dev/packages/file-storage/sql/postgresql/file-storage-package-create.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs.org-dev/packages/file-storage/sql/postgresql/file-storage-package-create.sql,v
diff -u -N -r1.1.1.4 -r1.1.1.5
--- openacs.org-dev/packages/file-storage/sql/postgresql/file-storage-package-create.sql	5 Aug 2002 21:38:50 -0000	1.1.1.4
+++ openacs.org-dev/packages/file-storage/sql/postgresql/file-storage-package-create.sql	8 Oct 2002 15:47:11 -0000	1.1.1.5
@@ -45,23 +45,22 @@
     v_package_id                fs_root_folders.package_id%TYPE;
     v_tree_sortkey              cr_items.tree_sortkey%TYPE;
 begin
-    select tree_ancestor_key(tree_sortkey, 2)
-    into v_tree_sortkey
-    from cr_items
-    where item_id = get_package_id__item_id;
 
     select fs_root_folders.package_id
     into v_package_id
     from fs_root_folders,
-         cr_items
-    where fs_root_folders.folder_id = cr_items.item_id
-    and cr_items.tree_sortkey = v_tree_sortkey;
+        (select cr_items.item_id 
+           from (select tree_ancestor_keys(cr_items_get_tree_sortkey(get_package_id__item_id)) as tree_sortkey) parents,
+             cr_items
+          where cr_items.tree_sortkey = parents.tree_sortkey) this
+    where fs_root_folders.folder_id = this.item_id;
 
     if NOT FOUND then
         return null;
     else
         return v_package_id;
     end if;
+
 end;' language 'plpgsql' with (iscachable);
 
 create function file_storage__new_root_folder (
@@ -360,7 +359,7 @@
                 v_new_lob_id := empty_lob();
 
                 -- copy the blob
-                select lob_copy(v_lob_id,v_new_lob_id);
+                perform lob_copy(v_lob_id,v_new_lob_id);
 
                 -- Update the lob id on the new version
                 update cr_revisions
@@ -403,7 +402,7 @@
         move_file__target_folder_id     alias for $2;
 begin
 
-        select content_item__move(
+        perform content_item__move(
                move_file__file_id,              -- item_id
                move_file__target_folder_id      -- target_folder_id
                );
@@ -438,8 +437,7 @@
       where folder_id = get_title__item_id;
   else if v_content_type = ''content_symlink'' 
        then
-         select label into v_title f
-         rom cr_symlinks 
+         select label into v_title from cr_symlinks 
          where symlink_id = get_title__item_id;
        else
          select name into v_title
@@ -452,7 +450,24 @@
 
 end;' language 'plpgsql';
 
+create function file_storage__get_parent_id (
+        integer --  item_id in cr_items.item_id%TYPE
+     ) returns integer as ' -- cr_items.item_id%TYPE
+     declare 
+         get_parent_id__item_id alias for $1;
+         v_parent_id          cr_items.item_id%TYPE;
+     begin
 
+         select parent_id
+         into v_parent_id
+         from cr_items
+         where item_id = get_parent_id__item_id;
+
+       return v_parent_id;
+
+end;'language 'plpgsql';
+
+
 create function file_storage__get_content_type (
        --
        -- Wrapper for content_item__get_content_type
