From 0de791ed760614991e7cb8a78fddd6874ea6919d Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Wed, 3 May 2017 21:25:01 -0400 Subject: Fix cursor_to_xml in tableforest false mode It only produced elements but no wrapping element. By contrast, cursor_to_xmlschema produced a schema that is now correct but did not previously match the XML data produced by cursor_to_xml. In passing, also fix a minor misunderstanding about moving cursors in the tests related to this. Reported-by: filip@jirsak.org Based-on-patch-by: Thomas Munro --- src/backend/utils/adt/xml.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/backend/utils/adt/xml.c') diff --git a/src/backend/utils/adt/xml.c b/src/backend/utils/adt/xml.c index 2f87151becc..42cffbbdd39 100644 --- a/src/backend/utils/adt/xml.c +++ b/src/backend/utils/adt/xml.c @@ -149,6 +149,10 @@ static int xml_xpathobjtoxmlarray(xmlXPathObjectPtr xpathobj, static xmlChar *pg_xmlCharStrndup(char *str, size_t len); #endif /* USE_LIBXML */ +static void xmldata_root_element_start(StringInfo result, const char *eltname, + const char *xmlschema, const char *targetns, + bool top_level); +static void xmldata_root_element_end(StringInfo result, const char *eltname); static StringInfo query_to_xml_internal(const char *query, char *tablename, const char *xmlschema, bool nulls, bool tableforest, const char *targetns, bool top_level); @@ -2451,6 +2455,12 @@ cursor_to_xml(PG_FUNCTION_ARGS) initStringInfo(&result); + if (!tableforest) + { + xmldata_root_element_start(&result, "table", NULL, targetns, true); + appendStringInfoChar(&result, '\n'); + } + SPI_connect(); portal = SPI_cursor_find(name); if (portal == NULL) @@ -2465,6 +2475,9 @@ cursor_to_xml(PG_FUNCTION_ARGS) SPI_finish(); + if (!tableforest) + xmldata_root_element_end(&result, "table"); + PG_RETURN_XML_P(stringinfo_to_xmltype(&result)); } -- cgit v1.2.3