[open-ils-commits] r11455 - in trunk/Open-ILS/src: perlmods/OpenILS/Application sql/Pg
svn at svn.open-ils.org
svn at svn.open-ils.org
Mon Dec 8 17:08:16 EST 2008
Author: erickson
Date: 2008-12-08 17:08:11 -0500 (Mon, 08 Dec 2008)
New Revision: 11455
Modified:
trunk/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm
trunk/Open-ILS/src/sql/Pg/020.schema.functions.sql
Log:
make the org-ancestor-setting proc return SETOF so that returning 0 rows is an option. update the cstore query that calls this proc to use the new-style call and re-use some code
Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm 2008-12-08 21:25:01 UTC (rev 11454)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm 2008-12-08 22:08:11 UTC (rev 11455)
@@ -1245,49 +1245,18 @@
sub ou_ancestor_setting_value {
my($self, $org_id, $name, $e) = @_;
$e = $e || OpenILS::Utils::CStoreEditor->new;
- my $query = {
- select => {
- aous => [ {
- transform => 'actor.org_unit_ancestor_setting',
- params => [$org_id],
- column => 'name',
- result_field => 'value',
- alias => 'value'
- } ]
- },
- from => 'aous',
- where => {name => $name},
- limit => 1 # since name is not required to be unique, this approach could return duplicate rows
- };
-
- my $obj = $e->json_query($query);
- return OpenSRF::Utils::JSON->JSON2perl($obj->[0]->{value}) if @$obj;
+ my $set = $self->ou_ancestor_setting($org_id, $name, $e);
+ return $set->{value} if $set;
return undef;
}
sub ou_ancestor_setting {
my( $self, $orgid, $name, $e ) = @_;
$e = $e || OpenILS::Utils::CStoreEditor->new;
-
- my $query = {
- select => {
- aous => [ {
- transform => 'actor.org_unit_ancestor_setting',
- params => [$orgid],
- column => 'name',
- result_field => 'id',
- alias => 'id'
- } ]
- },
- from => 'aous',
- where => {name => $name},
- limit => 1 # since name is not required to be unique, this approach could return duplicate rows
- };
-
- my $obj = $e->json_query($query);
- return undef unless @$obj;
- my $setting = $e->retrieve_actor_org_unit_setting($obj->[0]->{id});
- return { org => $setting->org_unit, value => OpenSRF::Utils::JSON->JSON2perl($setting->value) };
+ my $query = {from => ['actor.org_unit_ancestor_setting', $name, $orgid]};
+ my $setting = $e->json_query($query)->[0];
+ return undef unless $setting;
+ return {org => $setting->{org_unit}, value => OpenSRF::Utils::JSON->JSON2perl($setting->{value})};
}
Modified: trunk/Open-ILS/src/sql/Pg/020.schema.functions.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/020.schema.functions.sql 2008-12-08 21:25:01 UTC (rev 11454)
+++ trunk/Open-ILS/src/sql/Pg/020.schema.functions.sql 2008-12-08 22:08:11 UTC (rev 11455)
@@ -206,7 +206,7 @@
) z;
$$ LANGUAGE SQL STABLE;
-CREATE OR REPLACE FUNCTION actor.org_unit_ancestor_setting( setting_name TEXT, org_id INT ) RETURNS actor.org_unit_setting AS $$
+CREATE OR REPLACE FUNCTION actor.org_unit_ancestor_setting( setting_name TEXT, org_id INT ) RETURNS SETOF actor.org_unit_setting AS $$
DECLARE
setting RECORD;
cur_org INT;
@@ -215,13 +215,12 @@
LOOP
SELECT INTO setting * FROM actor.org_unit_setting WHERE org_unit = cur_org AND name = setting_name;
IF FOUND THEN
- RETURN setting;
+ RETURN NEXT setting;
END IF;
SELECT INTO cur_org parent_ou FROM actor.org_unit WHERE id = cur_org;
- IF cur_org IS NULL THEN
- RETURN NULL;
- END IF;
+ EXIT WHEN cur_org IS NULL;
END LOOP;
+ RETURN;
END;
$$ LANGUAGE plpgsql;
More information about the open-ils-commits
mailing list