From: miker Date: Sat, 16 Oct 2010 15:46:43 +0000 (+0000) Subject: Backport oils_text_as_bytea work from 2.0 X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=9ea639c7b6039f32a588c69ea6c7b3b6009c6cb6;p=Evergreen.git Backport oils_text_as_bytea work from 2.0 git-svn-id: svn://svn.open-ils.org/ILS/branches/rel_1_6@18368 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/asset.pm b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/asset.pm index 0ad5e8fa9b..5add0f4767 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/asset.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/asset.pm @@ -230,9 +230,9 @@ sub cn_browse_pagedown { $table cn where not deleted - and (cast(upper(label) as bytea) > ? or ( cn.id > ? and cast(upper(label) as bytea) = ? )) + and (oils_text_as_bytea(upper(label)) > ? or ( cn.id > ? and oils_text_as_bytea(upper(label)) = ? )) and owning_lib in ($orgs) - order by cast(upper(label) as bytea), 4, 2 + order by oils_text_as_bytea(upper(label)), 4, 2 limit $size; SQL @@ -285,9 +285,9 @@ sub cn_browse_pageup { $table cn where not deleted - and (cast(upper(label) as bytea) < ? or ( cn.id < ? and cast(upper(label) as bytea) = ? )) + and (oils_text_as_bytea(upper(label)) < ? or ( cn.id < ? and oils_text_as_bytea(upper(label)) = ? )) and owning_lib in ($orgs) - order by cast(upper(label) as bytea) desc, 4 desc, 2 desc + order by oils_text_as_bytea(upper(label)) desc, 4 desc, 2 desc limit $size ) as bar order by 1,4,2; @@ -343,9 +343,9 @@ sub cn_browse_target { $table cn where not deleted - and cast(upper(label) as bytea) < ? + and oils_text_as_bytea(upper(label)) < ? and owning_lib in ($orgs) - order by cast(upper(label) as bytea) desc, 4 desc, 2 desc + order by oils_text_as_bytea(upper(label)) desc, 4 desc, 2 desc limit $topsize ) as bar order by 1,4,2; @@ -361,9 +361,9 @@ sub cn_browse_target { $table cn where not deleted - and cast(upper(label) as bytea) >= ? + and oils_text_as_bytea(upper(label)) >= ? and owning_lib in ($orgs) - order by cast(upper(label) as bytea),4,2 + order by oils_text_as_bytea(upper(label)),4,2 limit $bottomsize; SQL diff --git a/Open-ILS/src/perlmods/OpenILS/Application/SuperCat.pm b/Open-ILS/src/perlmods/OpenILS/Application/SuperCat.pm index 6f617ae7d2..ec69b1a205 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/SuperCat.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/SuperCat.pm @@ -287,7 +287,7 @@ sub cn_browse { }, { flesh => 1, flesh_fields => { acn => [qw/record owning_lib/] }, - order_by => { acn => "cast(upper(label) as bytea) desc, id desc, owning_lib desc" }, + order_by => { acn => "oils_text_as_bytea(upper(label)) desc, id desc, owning_lib desc" }, limit => $before_limit, offset => abs($page) * $page_size - $before_offset, } @@ -304,7 +304,7 @@ sub cn_browse { }, { flesh => 1, flesh_fields => { acn => [qw/record owning_lib/] }, - order_by => { acn => "cast(upper(label) as bytea), id, owning_lib" }, + order_by => { acn => "oils_text_as_bytea(upper(label)), id, owning_lib" }, limit => $after_limit, offset => abs($page) * $page_size - $after_offset, } diff --git a/Open-ILS/src/sql/Pg/002.functions.config.sql b/Open-ILS/src/sql/Pg/002.functions.config.sql index ad94f8c522..a2f41b6db4 100644 --- a/Open-ILS/src/sql/Pg/002.functions.config.sql +++ b/Open-ILS/src/sql/Pg/002.functions.config.sql @@ -124,5 +124,9 @@ CREATE OR REPLACE FUNCTION public.first_word ( TEXT ) RETURNS TEXT AS $$ SELECT SUBSTRING( $1 FROM $_$^\S+$_$); $$ LANGUAGE SQL; +CREATE OR REPLACE FUNCTION oils_text_as_bytea (TEXT) RETURNS BYTEA AS $_$ + SELECT CAST(REGEXP_REPLACE($1, $$\\$$, $$\\\\$$, 'g') AS BYTEA); +$_$ LANGUAGE SQL IMMUTABLE; + COMMIT; diff --git a/Open-ILS/src/sql/Pg/040.schema.asset.sql b/Open-ILS/src/sql/Pg/040.schema.asset.sql index ad36cbd8b5..1913f82d91 100644 --- a/Open-ILS/src/sql/Pg/040.schema.asset.sql +++ b/Open-ILS/src/sql/Pg/040.schema.asset.sql @@ -158,7 +158,7 @@ CREATE INDEX asset_call_number_record_idx ON asset.call_number (record); CREATE INDEX asset_call_number_creator_idx ON asset.call_number (creator); CREATE INDEX asset_call_number_editor_idx ON asset.call_number (editor); CREATE INDEX asset_call_number_dewey_idx ON asset.call_number (public.call_number_dewey(label)); -CREATE INDEX asset_call_number_upper_label_id_owning_lib_idx ON asset.call_number (cast(upper(label) as bytea),id,owning_lib); +CREATE INDEX asset_call_number_upper_label_id_owning_lib_idx ON asset.call_number (oils_text_as_bytea(upper(label)),id,owning_lib); CREATE UNIQUE INDEX asset_call_number_label_once_per_lib ON asset.call_number (record, owning_lib, label) WHERE deleted IS FALSE; CREATE RULE protect_cn_delete AS ON DELETE TO asset.call_number DO INSTEAD UPDATE asset.call_number SET deleted = TRUE WHERE OLD.id = asset.call_number.id; diff --git a/Open-ILS/src/sql/Pg/1.6.1-1.6.2-upgrade-db.sql b/Open-ILS/src/sql/Pg/1.6.1-1.6.2-upgrade-db.sql index e62a65e6cb..4a9733538e 100644 --- a/Open-ILS/src/sql/Pg/1.6.1-1.6.2-upgrade-db.sql +++ b/Open-ILS/src/sql/Pg/1.6.1-1.6.2-upgrade-db.sql @@ -1,7 +1,11 @@ BEGIN; +CREATE OR REPLACE FUNCTION oils_text_as_bytea (TEXT) RETURNS BYTEA AS $_$ + SELECT CAST(REGEXP_REPLACE($1, $$\\$$, $$\\\\$$, 'g') AS BYTEA); +$_$ LANGUAGE SQL IMMUTABLE; + DROP INDEX asset.asset_call_number_upper_label_id_owning_lib_idx; -CREATE INDEX asset_call_number_upper_label_id_owning_lib_idx ON asset.call_number (cast(upper(label) as bytea),id,owning_lib); +CREATE INDEX asset_call_number_upper_label_id_owning_lib_idx ON asset.call_number (oils_text_as_bytea(upper(label)),id,owning_lib); /* this makes us require PG 8.3+ */ CREATE OR REPLACE FUNCTION oils_xpath ( TEXT, TEXT, ANYARRAY ) RETURNS TEXT[] AS 'SELECT XPATH( $1, $2::XML, $3 )::TEXT[];' LANGUAGE SQL IMMUTABLE;