1
0
mirror of https://github.com/postgres/postgres.git synced 2025-08-30 06:01:21 +03:00

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>
This commit is contained in:
Peter Eisentraut
2017-05-03 21:25:01 -04:00
parent 1b6db75ef2
commit a48d479083
4 changed files with 68 additions and 15 deletions

View File

@@ -146,6 +146,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);
@@ -2380,6 +2384,9 @@ cursor_to_xml(PG_FUNCTION_ARGS)
initStringInfo(&result);
if (!tableforest)
xmldata_root_element_start(&result, "table", NULL, targetns, true);
SPI_connect();
portal = SPI_cursor_find(name);
if (portal == NULL)
@@ -2394,6 +2401,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));
}