From: Dan Pearl Date: Fri, 15 Mar 2013 19:04:37 +0000 (-0400) Subject: LP#1155313: Repair generation of label_sortkey for monograph_part entries X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=551262d5360a14240a5e22c0b5d5cd5d2717cdfd;p=contrib%2FConifer.git LP#1155313: Repair generation of label_sortkey for monograph_part entries The evergreen.lpad_number_substrings function attempts to codify numeric fields within labels. It does this by finding the strings, padding them to a given size, and replacing them in the source string. For instance: 3 => 0000000003 15.4 => 00000000150000000004 The algorithm was fooled by repeated characters, like in 15.1: 15.1 => 00000000000000000150000000001 INCORRECT This change will result in the correct value. Signed-off-by: Dan Pearl Signed-off-by: Galen Charlton --- diff --git a/Open-ILS/src/sql/Pg/002.functions.config.sql b/Open-ILS/src/sql/Pg/002.functions.config.sql index 3dab7d9dea..077e9e8adf 100644 --- a/Open-ILS/src/sql/Pg/002.functions.config.sql +++ b/Open-ILS/src/sql/Pg/002.functions.config.sql @@ -538,15 +538,15 @@ CREATE OR REPLACE FUNCTION oils_text_as_bytea (TEXT) RETURNS BYTEA AS $_$ $_$ LANGUAGE SQL IMMUTABLE; CREATE OR REPLACE FUNCTION evergreen.lpad_number_substrings( TEXT, TEXT, INT ) RETURNS TEXT AS $$ - my $string = shift; - my $pad = shift; - my $len = shift; + my $string = shift; # Source string + my $pad = shift; # string to fill. Typically '0'. This should be a single character. + my $len = shift; # length of resultant padded field my $find = $len - 1; - while ($string =~ /(?:^|\D)(\d{1,$find})(?:$|\D)/) { - my $padded = $1; + while ($string =~ /(^|\D)(\d{1,$find})($|\D)/) { + my $padded = $2; $padded = $pad x ($len - length($padded)) . $padded; - $string =~ s/$1/$padded/sg; + $string = $` . $1 . $padded . $3 . $'; } return $string;