Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0de791e

Browse files
committed
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 correctbut did not previously match the XML data produced by cursor_to_xml.In passing, also fix a minor misunderstanding about moving cursors inthe tests related to this.Reported-by: filip@jirsak.orgBased-on-patch-by: Thomas Munro <thomas.munro@enterprisedb.com>
1 parent4dd4104 commit0de791e

File tree

4 files changed

+71
-15
lines changed

4 files changed

+71
-15
lines changed

‎src/backend/utils/adt/xml.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ static int xml_xpathobjtoxmlarray(xmlXPathObjectPtr xpathobj,
149149
staticxmlChar*pg_xmlCharStrndup(char*str,size_tlen);
150150
#endif/* USE_LIBXML */
151151

152+
staticvoidxmldata_root_element_start(StringInforesult,constchar*eltname,
153+
constchar*xmlschema,constchar*targetns,
154+
booltop_level);
155+
staticvoidxmldata_root_element_end(StringInforesult,constchar*eltname);
152156
staticStringInfoquery_to_xml_internal(constchar*query,char*tablename,
153157
constchar*xmlschema,boolnulls,booltableforest,
154158
constchar*targetns,booltop_level);
@@ -2451,6 +2455,12 @@ cursor_to_xml(PG_FUNCTION_ARGS)
24512455

24522456
initStringInfo(&result);
24532457

2458+
if (!tableforest)
2459+
{
2460+
xmldata_root_element_start(&result,"table",NULL,targetns, true);
2461+
appendStringInfoChar(&result,'\n');
2462+
}
2463+
24542464
SPI_connect();
24552465
portal=SPI_cursor_find(name);
24562466
if (portal==NULL)
@@ -2465,6 +2475,9 @@ cursor_to_xml(PG_FUNCTION_ARGS)
24652475

24662476
SPI_finish();
24672477

2478+
if (!tableforest)
2479+
xmldata_root_element_end(&result,"table");
2480+
24682481
PG_RETURN_XML_P(stringinfo_to_xmltype(&result));
24692482
}
24702483

‎src/test/regress/expected/xmlmap.out

Lines changed: 51 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -696,20 +696,58 @@ SELECT cursor_to_xml('xc'::refcursor, 5, false, true, '');
696696

697697
(1 row)
698698

699-
MOVE FIRST IN xc;
699+
SELECT cursor_to_xmlschema('xc'::refcursor, false, true, '');
700+
cursor_to_xmlschema
701+
----------------------------------------------------------------------------------------------
702+
<xsd:schema +
703+
xmlns:xsd="http://www.w3.org/2001/XMLSchema"> +
704+
+
705+
<xsd:simpleType name="INTEGER"> +
706+
<xsd:restriction base="xsd:int"> +
707+
<xsd:maxInclusive value="2147483647"/> +
708+
<xsd:minInclusive value="-2147483648"/> +
709+
</xsd:restriction> +
710+
</xsd:simpleType> +
711+
+
712+
<xsd:simpleType name="UDT.regression.pg_catalog.text"> +
713+
<xsd:restriction base="xsd:string"> +
714+
</xsd:restriction> +
715+
</xsd:simpleType> +
716+
+
717+
<xsd:complexType name="RowType"> +
718+
<xsd:sequence> +
719+
<xsd:element name="a" type="INTEGER" minOccurs="0"></xsd:element> +
720+
<xsd:element name="b" type="UDT.regression.pg_catalog.text" minOccurs="0"></xsd:element>+
721+
</xsd:sequence> +
722+
</xsd:complexType> +
723+
+
724+
<xsd:element name="row" type="RowType"/> +
725+
+
726+
</xsd:schema>
727+
(1 row)
728+
729+
MOVE BACKWARD ALL IN xc;
700730
SELECT cursor_to_xml('xc'::refcursor, 5, true, false, '');
701-
cursor_to_xml
702-
---------------
703-
<row> +
704-
<a>1</a> +
705-
<b>one</b> +
706-
</row> +
707-
+
708-
<row> +
709-
<a>2</a> +
710-
<b>two</b> +
711-
</row> +
712-
+
731+
cursor_to_xml
732+
---------------------------------------------------------------
733+
<table xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">+
734+
+
735+
<row> +
736+
<a>-1</a> +
737+
<b xsi:nil="true"/> +
738+
</row> +
739+
+
740+
<row> +
741+
<a>1</a> +
742+
<b>one</b> +
743+
</row> +
744+
+
745+
<row> +
746+
<a>2</a> +
747+
<b>two</b> +
748+
</row> +
749+
+
750+
</table> +
713751

714752
(1 row)
715753

‎src/test/regress/expected/xmlmap_1.out

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@ SELECT cursor_to_xml('xc'::refcursor, 5, false, true, '');
7878
ERROR: unsupported XML feature
7979
DETAIL: This functionality requires the server to be built with libxml support.
8080
HINT: You need to rebuild PostgreSQL using --with-libxml.
81-
MOVE FIRST IN xc;
81+
SELECT cursor_to_xmlschema('xc'::refcursor, false, true, '');
82+
ERROR: unsupported XML feature
83+
DETAIL: This functionality requires the server to be built with libxml support.
84+
HINT: You need to rebuild PostgreSQL using --with-libxml.
85+
MOVE BACKWARD ALL IN xc;
8286
SELECT cursor_to_xml('xc'::refcursor, 5, true, false, '');
8387
ERROR: unsupported XML feature
8488
DETAIL: This functionality requires the server to be built with libxml support.

‎src/test/regress/sql/xmlmap.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ SELECT query_to_xml_and_xmlschema('SELECT * FROM testxmlschema.test1', true, tru
3030

3131
DECLARE xc CURSOR WITH HOLD FORSELECT*FROMtestxmlschema.test1ORDER BY1,2;
3232
SELECT cursor_to_xml('xc'::refcursor,5, false, true,'');
33-
MOVE FIRSTIN xc;
33+
SELECT cursor_to_xmlschema('xc'::refcursor, false, true,'');
34+
MOVE BACKWARD ALLIN xc;
3435
SELECT cursor_to_xml('xc'::refcursor,5, true, false,'');
3536
SELECT cursor_to_xmlschema('xc'::refcursor, true, false,'');
3637

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp