Backport oils_text_as_bytea work from 2.0
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Sat, 16 Oct 2010 15:46:43 +0000 (15:46 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Sat, 16 Oct 2010 15:46:43 +0000 (15:46 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/branches/rel_1_6@18368 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/asset.pm
Open-ILS/src/perlmods/OpenILS/Application/SuperCat.pm
Open-ILS/src/sql/Pg/002.functions.config.sql
Open-ILS/src/sql/Pg/040.schema.asset.sql
Open-ILS/src/sql/Pg/1.6.1-1.6.2-upgrade-db.sql

index 0ad5e8f..5add0f4 100644 (file)
@@ -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
 
index 6f617ae..ec69b1a 100644 (file)
@@ -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,
                        }
index ad94f8c..a2f41b6 100644 (file)
@@ -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;
 
index ad36cbd..1913f82 100644 (file)
@@ -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;
 
index e62a65e..4a97335 100644 (file)
@@ -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;