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

Commit6e86b44

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 parent85b3bcb commit6e86b44

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
@@ -147,6 +147,10 @@ static int xml_xpathobjtoxmlarray(xmlXPathObjectPtr xpathobj,
147147
PgXmlErrorContext*xmlerrcxt);
148148
#endif/* USE_LIBXML */
149149

150+
staticvoidxmldata_root_element_start(StringInforesult,constchar*eltname,
151+
constchar*xmlschema,constchar*targetns,
152+
booltop_level);
153+
staticvoidxmldata_root_element_end(StringInforesult,constchar*eltname);
150154
staticStringInfoquery_to_xml_internal(constchar*query,char*tablename,
151155
constchar*xmlschema,boolnulls,booltableforest,
152156
constchar*targetns,booltop_level);
@@ -2388,6 +2392,12 @@ cursor_to_xml(PG_FUNCTION_ARGS)
23882392

23892393
initStringInfo(&result);
23902394

2395+
if (!tableforest)
2396+
{
2397+
xmldata_root_element_start(&result,"table",NULL,targetns, true);
2398+
appendStringInfoChar(&result,'\n');
2399+
}
2400+
23912401
SPI_connect();
23922402
portal=SPI_cursor_find(name);
23932403
if (portal==NULL)
@@ -2402,6 +2412,9 @@ cursor_to_xml(PG_FUNCTION_ARGS)
24022412

24032413
SPI_finish();
24042414

2415+
if (!tableforest)
2416+
xmldata_root_element_end(&result,"table");
2417+
24052418
PG_RETURN_XML_P(stringinfo_to_xmltype(&result));
24062419
}
24072420

‎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