summaryrefslogtreecommitdiff
path: root/src/backend/utils
diff options
context:
space:
mode:
authorPeter Eisentraut <peter_e@gmx.net>2017-05-03 21:25:01 -0400
committerPeter Eisentraut <peter_e@gmx.net>2017-05-04 21:31:12 -0400
commit6e86b448f2f700ab0a05afbeba80fbadfcd1d70a (patch)
tree31d9edac1a2bfdb968fde9af58129d729aa57d86 /src/backend/utils
parent85b3bcbcd61cc1b5aac35e53edc67abd1bceee08 (diff)
Fix cursor_to_xml in tableforest false mode
It only produced <row> elements but no wrapping <table> 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 <thomas.munro@enterprisedb.com>
Diffstat (limited to 'src/backend/utils')
-rw-r--r--src/backend/utils/adt/xml.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/backend/utils/adt/xml.c b/src/backend/utils/adt/xml.c
index 92a935ff63a..b27ab6a23c5 100644
--- a/src/backend/utils/adt/xml.c
+++ b/src/backend/utils/adt/xml.c
@@ -147,6 +147,10 @@ static int xml_xpathobjtoxmlarray(xmlXPathObjectPtr xpathobj,
PgXmlErrorContext *xmlerrcxt);
#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);
@@ -2388,6 +2392,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)
@@ -2402,6 +2412,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));
}