Index: openacs-4/packages/address-book/sql/postgresql/address-book-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/address-book/sql/postgresql/address-book-create.sql,v diff -u -r1.5 -r1.6 --- openacs-4/packages/address-book/sql/postgresql/address-book-create.sql 17 May 2003 10:10:13 -0000 1.5 +++ openacs-4/packages/address-book/sql/postgresql/address-book-create.sql 25 Jul 2004 11:18:28 -0000 1.6 @@ -425,11 +425,7 @@ end if; return v_attr_id; - end new; - ); - return v_attr_id; - end;' language 'plpgsql'; @@ -638,18 +634,16 @@ -- If they supplied an object_id, relate it: -- if object_id is not null then v_rel_id := - ab_contact_rel.new( + ab_contact_rel__new( null, -- rel_id null, -- rel_type new__object_id, -- object_id_one v_contact_id, -- object_id_two new__creation_user,-- creation_user new__creation_ip, -- creation_ip new__category -- category -); + ); - end if; - insert into ab_contacts (contact_id, first_names, last_name, title, organization) @@ -681,16 +675,20 @@ end;' language 'plpgsql'; create function ab_contact__delete_orphan_address(integer) returns integer as ' - declare - v_rel_id subplace_rels.rel_id%TYPE; + v_rel_id integer; begin - select sr.rel_id - from subplace_rels sr, acs_rels ar - where ar.rel_id = sr.rel_id and ar.object_id_two = :address_id; - if found then - subplace_rel__delete(v_rel_id); - pl_address__delete(:address_id); + raise exception ''ab_contact__delete_orphan_address NOT IMPLEMENTED''; + + if exists ( select sr.rel_id + from subplace_rels sr, acs_rels ar + where ar.rel_id = sr.rel_id and ar.object_id_two = v_rel_id) then + + PERFORM subplace_rel__delete(v_rel_id); + + PERFORM pl_address__delete(v_rel_id); + + end if; end;' language 'plpgsql'; @@ -703,7 +701,7 @@ contact_id alias for $1; delete_orphan_addresses_p alias for $2; v_ab_contact_attrs_row ab_contact_attrs%ROWTYPE; - v_addresses_located_row pl_addresses_located%ROWTYPE; + v_addresses_located_row record; -- pl_addresses_located%ROWTYPE; v_rel_id ab_contact_rels.rel_id%TYPE; begin @@ -713,24 +711,25 @@ from ab_contact_attrs where contact_id = ab_contact.delete.contact_id) loop - ab_contact_attr__delete(v_ab_contact_attrs_row.attr_id); + PERFORM ab_contact_attr__delete(v_ab_contact_attrs_row.attr_id); end loop; for v_addresses_located_row in (select * from pl_addresses_located where locatee_id = ab_contact.delete.contact_id) loop - subplace_rel__delete(v_addresses_located_row.rel_id); + PERFORM subplace_rel__delete(v_addresses_located_row.rel_id); if delete_orphan_addresses_p and - not exists(select 1 + not exists (select 1 from place_element_map pem, pl_address pl where pem.place_id = pl.address_id and v_addresses_located_row.address_id = pl.address_id) then select sr.rel_id into v_rel_id from subplace_rels sr, acs_rels ar where ar.rel_id = sr.rel_id and ar.object_id_two = v_addresses_located_row.address_id; - if found then - subplace_rel__delete(v_rel_id); + if v_rel_id is not null then + PERFORM subplace_rel__delete(v_rel_id); end if; end if; + end loop; return 0; end;' language 'plpgsql';