[open-ils-commits] r20016 - branches/rel_2_0/Open-ILS/src/sql/Pg (gmc)
svn at svn.open-ils.org
svn at svn.open-ils.org
Thu Apr 7 12:03:49 EDT 2011
Author: gmc
Date: 2011-04-07 12:03:46 -0400 (Thu, 07 Apr 2011)
New Revision: 20016
Modified:
branches/rel_2_0/Open-ILS/src/sql/Pg/000.functions.general.sql
branches/rel_2_0/Open-ILS/src/sql/Pg/002.functions.config.sql
branches/rel_2_0/Open-ILS/src/sql/Pg/002.schema.config.sql
Log:
further fixes to maintain_901
Now correctly handles &, <, or > appearing in the tcn_value
or tcn_source. Also introduces a trivial utility stored
function, evergreen.xml_escape():
evergreen.xml_escape(TEXT) returns TEXT: converts '&', '<',
and '>' to XML entities
Signed-off-by: Galen Charlton <gmc at esilibrary.com>
Modified: branches/rel_2_0/Open-ILS/src/sql/Pg/000.functions.general.sql
===================================================================
--- branches/rel_2_0/Open-ILS/src/sql/Pg/000.functions.general.sql 2011-04-07 15:50:57 UTC (rev 20015)
+++ branches/rel_2_0/Open-ILS/src/sql/Pg/000.functions.general.sql 2011-04-07 16:03:46 UTC (rev 20016)
@@ -11,6 +11,13 @@
return lc(shift);
$$ LANGUAGE PLPERLU STRICT IMMUTABLE;
+CREATE OR REPLACE FUNCTION evergreen.xml_escape(str TEXT) RETURNS text AS $$
+ SELECT REPLACE(REPLACE(REPLACE($1,
+ '&', '&'),
+ '<', '<'),
+ '>', '>');
+$$ LANGUAGE SQL IMMUTABLE;
+
CREATE OR REPLACE FUNCTION evergreen.change_db_setting(setting_name TEXT, settings TEXT[]) RETURNS VOID AS $$
BEGIN
EXECUTE 'ALTER DATABASE ' || quote_ident(current_database()) || ' SET ' || quote_ident(setting_name) || ' = ' || array_to_string(settings, ',');
Modified: branches/rel_2_0/Open-ILS/src/sql/Pg/002.functions.config.sql
===================================================================
--- branches/rel_2_0/Open-ILS/src/sql/Pg/002.functions.config.sql 2011-04-07 15:50:57 UTC (rev 20015)
+++ branches/rel_2_0/Open-ILS/src/sql/Pg/002.functions.config.sql 2011-04-07 16:03:46 UTC (rev 20016)
@@ -422,8 +422,6 @@
CREATE OR REPLACE FUNCTION maintain_901 () RETURNS TRIGGER AS $func$
DECLARE
use_id_for_tcn BOOLEAN;
- norm_tcn_value TEXT;
- norm_tcn_source TEXT;
BEGIN
-- Remove any existing 901 fields before we insert the authoritative one
NEW.marc := REGEXP_REPLACE(NEW.marc, E'<datafield[^>]*?tag="901".+?</datafield>', '', 'g');
@@ -435,21 +433,14 @@
IF use_id_for_tcn = 't' THEN
NEW.tcn_value := NEW.id;
- norm_tcn_value := NEW.tcn_value;
- ELSE
- -- yes, ampersands can show up in tcn_values ...
- norm_tcn_value := REGEXP_REPLACE(NEW.tcn_value, E'&(?!\\S+;)', '&', 'g');
END IF;
- -- ... and TCN sources
- -- FIXME we have here yet another (stub) version of entityize
- norm_tcn_source := REGEXP_REPLACE(NEW.tcn_source, E'&(?!\\S+;)', '&', 'g');
NEW.marc := REGEXP_REPLACE(
NEW.marc,
E'(</(?:[^:]*?:)?record>)',
E'<datafield tag="901" ind1=" " ind2=" ">' ||
- '<subfield code="a">' || norm_tcn_value || E'</subfield>' ||
- '<subfield code="b">' || norm_tcn_source || E'</subfield>' ||
+ '<subfield code="a">' || evergreen.xml_escape(NEW.tcn_value) || E'</subfield>' ||
+ '<subfield code="b">' || evergreen.xml_escape(NEW.tcn_source) || E'</subfield>' ||
'<subfield code="c">' || NEW.id || E'</subfield>' ||
'<subfield code="t">' || TG_TABLE_SCHEMA || E'</subfield>' ||
CASE WHEN NEW.owner IS NOT NULL THEN '<subfield code="o">' || NEW.owner || E'</subfield>' ELSE '' END ||
Modified: branches/rel_2_0/Open-ILS/src/sql/Pg/002.schema.config.sql
===================================================================
--- branches/rel_2_0/Open-ILS/src/sql/Pg/002.schema.config.sql 2011-04-07 15:50:57 UTC (rev 20015)
+++ branches/rel_2_0/Open-ILS/src/sql/Pg/002.schema.config.sql 2011-04-07 16:03:46 UTC (rev 20016)
@@ -70,7 +70,7 @@
install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
);
-INSERT INTO config.upgrade_log (version) VALUES ('0508'); -- gmc
+INSERT INTO config.upgrade_log (version) VALUES ('0509'); -- gmc
CREATE TABLE config.bib_source (
id SERIAL PRIMARY KEY,
More information about the open-ils-commits
mailing list