diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/catalog/sql_features.txt | 2 | ||||
-rw-r--r-- | src/backend/utils/adt/xml.c | 22 | ||||
-rw-r--r-- | src/include/catalog/pg_proc.dat | 3 | ||||
-rw-r--r-- | src/test/regress/expected/xml.out | 36 | ||||
-rw-r--r-- | src/test/regress/expected/xml_1.out | 23 | ||||
-rw-r--r-- | src/test/regress/expected/xml_2.out | 36 | ||||
-rw-r--r-- | src/test/regress/sql/xml.sql | 7 |
7 files changed, 128 insertions, 1 deletions
diff --git a/src/backend/catalog/sql_features.txt b/src/backend/catalog/sql_features.txt index b33065d7bf7..80c40eaf578 100644 --- a/src/backend/catalog/sql_features.txt +++ b/src/backend/catalog/sql_features.txt @@ -633,7 +633,7 @@ X034 XMLAgg YES X035 XMLAgg: ORDER BY option YES X036 XMLComment YES X037 XMLPI YES -X038 XMLText NO +X038 XMLText YES supported except for RETURNING X040 Basic table mapping YES X041 Basic table mapping: null absent YES X042 Basic table mapping: null as nil YES diff --git a/src/backend/utils/adt/xml.c b/src/backend/utils/adt/xml.c index 2300c7ebf34..c401e7b8219 100644 --- a/src/backend/utils/adt/xml.c +++ b/src/backend/utils/adt/xml.c @@ -47,6 +47,7 @@ #ifdef USE_LIBXML #include <libxml/chvalid.h> +#include <libxml/entities.h> #include <libxml/parser.h> #include <libxml/parserInternals.h> #include <libxml/tree.h> @@ -513,6 +514,27 @@ xmlcomment(PG_FUNCTION_ARGS) } +Datum +xmltext(PG_FUNCTION_ARGS) +{ +#ifdef USE_LIBXML + text *arg = PG_GETARG_TEXT_PP(0); + text *result; + xmlChar *xmlbuf = NULL; + + xmlbuf = xmlEncodeSpecialChars(NULL, xml_text2xmlChar(arg)); + + Assert(xmlbuf); + + result = cstring_to_text_with_len((const char *) xmlbuf, xmlStrlen(xmlbuf)); + xmlFree(xmlbuf); + PG_RETURN_XML_P(result); +#else + NO_XML_SUPPORT(); + return 0; +#endif /* not USE_LIBXML */ +} + /* * TODO: xmlconcat needs to merge the notations and unparsed entities diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat index 091f7e343c3..f14aed422a7 100644 --- a/src/include/catalog/pg_proc.dat +++ b/src/include/catalog/pg_proc.dat @@ -8793,6 +8793,9 @@ { oid => '2922', descr => 'serialize an XML value to a character string', proname => 'text', prorettype => 'text', proargtypes => 'xml', prosrc => 'xmltotext' }, +{ oid => '3813', descr => 'generate XML text node', + proname => 'xmltext', proisstrict => 't', prorettype => 'xml', + proargtypes => 'text', prosrc => 'xmltext' }, { oid => '2923', descr => 'map table contents to XML', proname => 'table_to_xml', procost => '100', provolatile => 's', diff --git a/src/test/regress/expected/xml.out b/src/test/regress/expected/xml.out index 398345ca67f..13e4296bf8f 100644 --- a/src/test/regress/expected/xml.out +++ b/src/test/regress/expected/xml.out @@ -1785,3 +1785,39 @@ SELECT * FROM XMLTABLE('.' PASSING XMLELEMENT(NAME a) columns a varchar(20) PATH <foo/> | <foo/> (1 row) +SELECT xmltext(NULL); + xmltext +--------- + +(1 row) + +SELECT xmltext(''); + xmltext +--------- + +(1 row) + +SELECT xmltext(' '); + xmltext +--------- + +(1 row) + +SELECT xmltext('foo `$_-+?=*^%!|/\()[]{}'); + xmltext +-------------------------- + foo `$_-+?=*^%!|/\()[]{} +(1 row) + +SELECT xmltext('foo & <"bar">'); + xmltext +----------------------------------- + foo & <"bar"> +(1 row) + +SELECT xmltext('x'|| '<P>73</P>'::xml || .42 || true || 'j'::char); + xmltext +--------------------------------- + x<P>73</P>0.42truej +(1 row) + diff --git a/src/test/regress/expected/xml_1.out b/src/test/regress/expected/xml_1.out index 63b779470ff..eb9c6f2ed41 100644 --- a/src/test/regress/expected/xml_1.out +++ b/src/test/regress/expected/xml_1.out @@ -1402,3 +1402,26 @@ DETAIL: This functionality requires the server to be built with libxml support. SELECT * FROM XMLTABLE('.' PASSING XMLELEMENT(NAME a) columns a varchar(20) PATH '"<foo/>"', b xml PATH '"<foo/>"'); ERROR: unsupported XML feature DETAIL: This functionality requires the server to be built with libxml support. +SELECT xmltext(NULL); + xmltext +--------- + +(1 row) + +SELECT xmltext(''); +ERROR: unsupported XML feature +DETAIL: This functionality requires the server to be built with libxml support. +SELECT xmltext(' '); +ERROR: unsupported XML feature +DETAIL: This functionality requires the server to be built with libxml support. +SELECT xmltext('foo `$_-+?=*^%!|/\()[]{}'); +ERROR: unsupported XML feature +DETAIL: This functionality requires the server to be built with libxml support. +SELECT xmltext('foo & <"bar">'); +ERROR: unsupported XML feature +DETAIL: This functionality requires the server to be built with libxml support. +SELECT xmltext('x'|| '<P>73</P>'::xml || .42 || true || 'j'::char); +ERROR: unsupported XML feature +LINE 1: SELECT xmltext('x'|| '<P>73</P>'::xml || .42 || true || 'j':... + ^ +DETAIL: This functionality requires the server to be built with libxml support. diff --git a/src/test/regress/expected/xml_2.out b/src/test/regress/expected/xml_2.out index 43c2558352a..c8ed8e0cfa6 100644 --- a/src/test/regress/expected/xml_2.out +++ b/src/test/regress/expected/xml_2.out @@ -1765,3 +1765,39 @@ SELECT * FROM XMLTABLE('.' PASSING XMLELEMENT(NAME a) columns a varchar(20) PATH <foo/> | <foo/> (1 row) +SELECT xmltext(NULL); + xmltext +--------- + +(1 row) + +SELECT xmltext(''); + xmltext +--------- + +(1 row) + +SELECT xmltext(' '); + xmltext +--------- + +(1 row) + +SELECT xmltext('foo `$_-+?=*^%!|/\()[]{}'); + xmltext +-------------------------- + foo `$_-+?=*^%!|/\()[]{} +(1 row) + +SELECT xmltext('foo & <"bar">'); + xmltext +----------------------------------- + foo & <"bar"> +(1 row) + +SELECT xmltext('x'|| '<P>73</P>'::xml || .42 || true || 'j'::char); + xmltext +--------------------------------- + x<P>73</P>0.42truej +(1 row) + diff --git a/src/test/regress/sql/xml.sql b/src/test/regress/sql/xml.sql index a591eea2e5d..bd4a4e7acdf 100644 --- a/src/test/regress/sql/xml.sql +++ b/src/test/regress/sql/xml.sql @@ -660,3 +660,10 @@ SELECT * FROM XMLTABLE('*' PASSING '<e>pre<!--c1--><?pi arg?><![CDATA[&ent1]]><n \x SELECT * FROM XMLTABLE('.' PASSING XMLELEMENT(NAME a) columns a varchar(20) PATH '"<foo/>"', b xml PATH '"<foo/>"'); + +SELECT xmltext(NULL); +SELECT xmltext(''); +SELECT xmltext(' '); +SELECT xmltext('foo `$_-+?=*^%!|/\()[]{}'); +SELECT xmltext('foo & <"bar">'); +SELECT xmltext('x'|| '<P>73</P>'::xml || .42 || true || 'j'::char);
\ No newline at end of file |