From: Bill Erickson Date: Fri, 9 Dec 2011 14:48:36 +0000 (-0500) Subject: address alert : DB func added to schema X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=d03ae3a2fc4cf9d94b4236735d2e8a98857db9c4;p=evergreen%2Fequinox.git address alert : DB func added to schema Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/src/sql/Pg/999.functions.global.sql b/Open-ILS/src/sql/Pg/999.functions.global.sql index 4eff147ebf..1ce50e16ec 100644 --- a/Open-ILS/src/sql/Pg/999.functions.global.sql +++ b/Open-ILS/src/sql/Pg/999.functions.global.sql @@ -2035,3 +2035,35 @@ for my $key ( keys %map ) { return $default; $f$ LANGUAGE PLPERLU; + +CREATE OR REPLACE FUNCTION actor.address_alert_matches + (org_unit INT, street1 TEXT, street2 TEXT, city TEXT, county TEXT, state TEXT, country TEXT, post_code TEXT) + RETURNS SETOF actor.address_alert AS $$ +SELECT * +FROM actor.address_alert +WHERE + owner IN (SELECT id FROM actor.org_unit_ancestors($1)) AND ( + ( + match_all + AND LOWER(COALESCE($2, '')) ~ LOWER(COALESCE(street1, '.*')) + AND LOWER(COALESCE($3, '')) ~ LOWER(COALESCE(street2, '.*')) + AND LOWER(COALESCE($4, '')) ~ LOWER(COALESCE(city, '.*')) + AND LOWER(COALESCE($5, '')) ~ LOWER(COALESCE(county, '.*')) + AND LOWER(COALESCE($6, '')) ~ LOWER(COALESCE(state, '.*')) + AND LOWER(COALESCE($7, '')) ~ LOWER(COALESCE(country, '.*')) + AND LOWER(COALESCE($8, '')) ~ LOWER(COALESCE(post_code, '.*')) + ) OR ( + NOT match_all AND ( + LOWER($2) ~ LOWER(street1) + OR LOWER($3) ~ LOWER(street2) + OR LOWER($4) ~ LOWER(city) + OR LOWER($5) ~ LOWER(county) + OR LOWER($6) ~ LOWER(state) + OR LOWER($7) ~ LOWER(country) + OR LOWER($8) ~ LOWER(post_code) + ) + ) + ) + ORDER BY actor.org_unit_proximity(owner, $1) +$$ LANGUAGE SQL; +