From c4d8b72de07a7fafc061e6904a9eafd6eefa684d Mon Sep 17 00:00:00 2001 From: erickson Date: Wed, 14 Jan 2009 21:49:46 +0000 Subject: [PATCH] stored proc to replace an address with its pending address git-svn-id: svn://svn.open-ils.org/ILS/trunk@11829 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/sql/Pg/999.functions.global.sql | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Open-ILS/src/sql/Pg/999.functions.global.sql b/Open-ILS/src/sql/Pg/999.functions.global.sql index 723667abdd..8f6c6e62fc 100644 --- a/Open-ILS/src/sql/Pg/999.functions.global.sql +++ b/Open-ILS/src/sql/Pg/999.functions.global.sql @@ -165,3 +165,29 @@ COMMENT ON FUNCTION actor.usr_merge(INT, INT) IS $$ */ $$; + + +CREATE OR REPLACE FUNCTION actor.approve_pending_address(pending_id INT) RETURNS VOID AS $$ +DECLARE + old_id INT; +BEGIN + SELECT INTO old_id replaces FROM actor.usr_address where id = pending_id; + IF old_id IS NULL THEN + RAISE NOTICE 'Address % does not replace any address', pending_id; + RETURN; + END IF; + DELETE FROM actor.usr_address WHERE id = -old_id; + UPDATE actor.usr_address SET id = -id WHERE id = old_id; + UPDATE actor.usr_address SET replaces = NULL, id = old_id WHERE id = pending_id; +END +$$ LANGUAGE plpgsql; + +COMMENT ON FUNCTION actor.approve_pending_address(INT) IS $$ +/** + * Replaces an address with a pending address. This is done by giving the pending + * address the ID of the old address. The replaced address is retained with -id. + */ +$$; + + + -- 2.11.0