From 042a3f95d07f828cd9e31ba593c7db8e43d3ab8e Mon Sep 17 00:00:00 2001 From: erickson Date: Tue, 6 Jul 2010 15:42:26 +0000 Subject: [PATCH] added stored proc to return the distinct set of target copies from a users visible circ history git-svn-id: svn://svn.open-ils.org/ILS/trunk@16849 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/sql/Pg/002.schema.config.sql | 2 +- Open-ILS/src/sql/Pg/090.schema.action.sql | 10 ++++++++++ .../Pg/upgrade/0324.schema.usr_visible_circ_copies.sql | 16 ++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 Open-ILS/src/sql/Pg/upgrade/0324.schema.usr_visible_circ_copies.sql diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql index 5e6bdcf734..402ac70165 100644 --- a/Open-ILS/src/sql/Pg/002.schema.config.sql +++ b/Open-ILS/src/sql/Pg/002.schema.config.sql @@ -68,7 +68,7 @@ CREATE TABLE config.upgrade_log ( install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW() ); -INSERT INTO config.upgrade_log (version) VALUES ('0323'); -- senator +INSERT INTO config.upgrade_log (version) VALUES ('0324'); -- berick CREATE TABLE config.bib_source ( id SERIAL PRIMARY KEY, diff --git a/Open-ILS/src/sql/Pg/090.schema.action.sql b/Open-ILS/src/sql/Pg/090.schema.action.sql index f575055340..3892e4796a 100644 --- a/Open-ILS/src/sql/Pg/090.schema.action.sql +++ b/Open-ILS/src/sql/Pg/090.schema.action.sql @@ -616,6 +616,16 @@ BEGIN END; $func$ LANGUAGE PLPGSQL; +CREATE OR REPLACE FUNCTION action.usr_visible_circ_copies( user_id INTEGER ) RETURNS SETOF INTEGER AS $$ + DECLARE + copy INTEGER; + BEGIN + FOR copy IN SELECT DISTINCT(target_copy) FROM action.usr_visible_circs(user_id) LOOP + RETURN NEXT copy; + END LOOP; + END; +$$ LANGUAGE plpgsql; + CREATE OR REPLACE FUNCTION action.usr_visible_holds (usr_id INT) RETURNS SETOF action.hold_request AS $func$ DECLARE h action.hold_request%ROWTYPE; diff --git a/Open-ILS/src/sql/Pg/upgrade/0324.schema.usr_visible_circ_copies.sql b/Open-ILS/src/sql/Pg/upgrade/0324.schema.usr_visible_circ_copies.sql new file mode 100644 index 0000000000..d4da54b6f2 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/0324.schema.usr_visible_circ_copies.sql @@ -0,0 +1,16 @@ +BEGIN; + +INSERT INTO config.upgrade_log (version) VALUES ('0324'); + +-- returns the distinct set of target copy IDs from a user's visible circulation history +CREATE OR REPLACE FUNCTION action.usr_visible_circ_copies( user_id INTEGER ) RETURNS SETOF INTEGER AS $$ + DECLARE + copy INTEGER; + BEGIN + FOR copy IN SELECT DISTINCT(target_copy) FROM action.usr_visible_circs(user_id) LOOP + RETURN NEXT copy; + END LOOP; + END; +$$ LANGUAGE plpgsql; + +COMMIT; -- 2.11.0