mirror of
https://github.com/postgres/postgres.git
synced 2025-05-02 11:44:50 +03:00
Fix incorrect xmlschema output for types timetz and timestamptz.
The output of table_to_xmlschema() and allied functions includes a regex describing valid values for these types ... but the regex was itself invalid, as it failed to escape a literal "+" sign. Report and fix by Renan Soares Lopes. Back-patch to all supported branches. Discussion: https://postgr.es/m/7f6fabaa-3f8f-49ab-89ca-59fbfe633105@me.com
This commit is contained in:
parent
1d072bd203
commit
ae8ec7feba
@ -3659,7 +3659,7 @@ map_sql_type_to_xmlschema_type(Oid typeoid, int typmod)
|
||||
case TIMEOID:
|
||||
case TIMETZOID:
|
||||
{
|
||||
const char *tz = (typeoid == TIMETZOID ? "(+|-)\\p{Nd}{2}:\\p{Nd}{2}" : "");
|
||||
const char *tz = (typeoid == TIMETZOID ? "(\\+|-)\\p{Nd}{2}:\\p{Nd}{2}" : "");
|
||||
|
||||
if (typmod == -1)
|
||||
appendStringInfo(&result,
|
||||
@ -3682,7 +3682,7 @@ map_sql_type_to_xmlschema_type(Oid typeoid, int typmod)
|
||||
case TIMESTAMPOID:
|
||||
case TIMESTAMPTZOID:
|
||||
{
|
||||
const char *tz = (typeoid == TIMESTAMPTZOID ? "(+|-)\\p{Nd}{2}:\\p{Nd}{2}" : "");
|
||||
const char *tz = (typeoid == TIMESTAMPTZOID ? "(\\+|-)\\p{Nd}{2}:\\p{Nd}{2}" : "");
|
||||
|
||||
if (typmod == -1)
|
||||
appendStringInfo(&result,
|
||||
|
@ -2,9 +2,15 @@ CREATE SCHEMA testxmlschema;
|
||||
CREATE TABLE testxmlschema.test1 (a int, b text);
|
||||
INSERT INTO testxmlschema.test1 VALUES (1, 'one'), (2, 'two'), (-1, null);
|
||||
CREATE DOMAIN testxmldomain AS varchar;
|
||||
CREATE TABLE testxmlschema.test2 (z int, y varchar(500), x char(6), w numeric(9,2), v smallint, u bigint, t real, s time, r timestamp, q date, p xml, o testxmldomain, n bool, m bytea, aaa text);
|
||||
CREATE TABLE testxmlschema.test2 (z int, y varchar(500), x char(6),
|
||||
w numeric(9,2), v smallint, u bigint, t real,
|
||||
s time, stz timetz, r timestamp, rtz timestamptz, q date,
|
||||
p xml, o testxmldomain, n bool, m bytea, aaa text);
|
||||
ALTER TABLE testxmlschema.test2 DROP COLUMN aaa;
|
||||
INSERT INTO testxmlschema.test2 VALUES (55, 'abc', 'def', 98.6, 2, 999, 0, '21:07', '2009-06-08 21:07:30', '2009-06-08', NULL, 'ABC', true, 'XYZ');
|
||||
INSERT INTO testxmlschema.test2 VALUES (55, 'abc', 'def',
|
||||
98.6, 2, 999, 0,
|
||||
'21:07', '21:11 +05', '2009-06-08 21:07:30', '2009-06-08 21:07:30 -07', '2009-06-08',
|
||||
NULL, 'ABC', true, 'XYZ');
|
||||
SELECT table_to_xml('testxmlschema.test1', false, false, '');
|
||||
table_to_xml
|
||||
---------------------------------------------------------------
|
||||
@ -107,7 +113,9 @@ SELECT table_to_xml('testxmlschema.test2', false, false, '');
|
||||
<u>999</u> +
|
||||
<t>0</t> +
|
||||
<s>21:07:00</s> +
|
||||
<stz>21:11:00+05</stz> +
|
||||
<r>2009-06-08T21:07:30</r> +
|
||||
<rtz>2009-06-08T21:07:30-07:00</rtz> +
|
||||
<q>2009-06-08</q> +
|
||||
<o>ABC</o> +
|
||||
<n>true</n> +
|
||||
@ -254,7 +262,7 @@ SELECT table_to_xmlschema('testxmlschema.test1', true, true, '');
|
||||
|
||||
SELECT table_to_xmlschema('testxmlschema.test2', false, false, '');
|
||||
table_to_xmlschema
|
||||
-----------------------------------------------------------------------------------------------------------------
|
||||
----------------------------------------------------------------------------------------------------------------------------
|
||||
<xsd:schema +
|
||||
xmlns:xsd="http://www.w3.org/2001/XMLSchema"> +
|
||||
+
|
||||
@ -302,12 +310,24 @@ SELECT table_to_xmlschema('testxmlschema.test2', false, false, '');
|
||||
</xsd:restriction> +
|
||||
</xsd:simpleType> +
|
||||
+
|
||||
<xsd:simpleType name="TIME_WTZ"> +
|
||||
<xsd:restriction base="xsd:time"> +
|
||||
<xsd:pattern value="\p{Nd}{2}:\p{Nd}{2}:\p{Nd}{2}(.\p{Nd}+)?(\+|-)\p{Nd}{2}:\p{Nd}{2}"/> +
|
||||
</xsd:restriction> +
|
||||
</xsd:simpleType> +
|
||||
+
|
||||
<xsd:simpleType name="TIMESTAMP"> +
|
||||
<xsd:restriction base="xsd:dateTime"> +
|
||||
<xsd:pattern value="\p{Nd}{4}-\p{Nd}{2}-\p{Nd}{2}T\p{Nd}{2}:\p{Nd}{2}:\p{Nd}{2}(.\p{Nd}+)?"/> +
|
||||
</xsd:restriction> +
|
||||
</xsd:simpleType> +
|
||||
+
|
||||
<xsd:simpleType name="TIMESTAMP_WTZ"> +
|
||||
<xsd:restriction base="xsd:dateTime"> +
|
||||
<xsd:pattern value="\p{Nd}{4}-\p{Nd}{2}-\p{Nd}{2}T\p{Nd}{2}:\p{Nd}{2}:\p{Nd}{2}(.\p{Nd}+)?(\+|-)\p{Nd}{2}:\p{Nd}{2}"/>+
|
||||
</xsd:restriction> +
|
||||
</xsd:simpleType> +
|
||||
+
|
||||
<xsd:simpleType name="DATE"> +
|
||||
<xsd:restriction base="xsd:date"> +
|
||||
<xsd:pattern value="\p{Nd}{4}-\p{Nd}{2}-\p{Nd}{2}"/> +
|
||||
@ -343,7 +363,9 @@ SELECT table_to_xmlschema('testxmlschema.test2', false, false, '');
|
||||
<xsd:element name="u" type="BIGINT" minOccurs="0"></xsd:element> +
|
||||
<xsd:element name="t" type="REAL" minOccurs="0"></xsd:element> +
|
||||
<xsd:element name="s" type="TIME" minOccurs="0"></xsd:element> +
|
||||
<xsd:element name="stz" type="TIME_WTZ" minOccurs="0"></xsd:element> +
|
||||
<xsd:element name="r" type="TIMESTAMP" minOccurs="0"></xsd:element> +
|
||||
<xsd:element name="rtz" type="TIMESTAMP_WTZ" minOccurs="0"></xsd:element> +
|
||||
<xsd:element name="q" type="DATE" minOccurs="0"></xsd:element> +
|
||||
<xsd:element name="p" type="XML" minOccurs="0"></xsd:element> +
|
||||
<xsd:element name="o" type="Domain.regression.public.testxmldomain" minOccurs="0"></xsd:element> +
|
||||
@ -816,7 +838,9 @@ SELECT schema_to_xml('testxmlschema', false, true, '');
|
||||
<u>999</u> +
|
||||
<t>0</t> +
|
||||
<s>21:07:00</s> +
|
||||
<stz>21:11:00+05</stz> +
|
||||
<r>2009-06-08T21:07:30</r> +
|
||||
<rtz>2009-06-08T21:07:30-07:00</rtz> +
|
||||
<q>2009-06-08</q> +
|
||||
<o>ABC</o> +
|
||||
<n>true</n> +
|
||||
@ -863,7 +887,9 @@ SELECT schema_to_xml('testxmlschema', true, false, '');
|
||||
<u>999</u> +
|
||||
<t>0</t> +
|
||||
<s>21:07:00</s> +
|
||||
<stz>21:11:00+05</stz> +
|
||||
<r>2009-06-08T21:07:30</r> +
|
||||
<rtz>2009-06-08T21:07:30-07:00</rtz> +
|
||||
<q>2009-06-08</q> +
|
||||
<p xsi:nil="true"/> +
|
||||
<o>ABC</o> +
|
||||
@ -879,7 +905,7 @@ SELECT schema_to_xml('testxmlschema', true, false, '');
|
||||
|
||||
SELECT schema_to_xmlschema('testxmlschema', false, true, '');
|
||||
schema_to_xmlschema
|
||||
-------------------------------------------------------------------------------------------------------------------
|
||||
----------------------------------------------------------------------------------------------------------------------------
|
||||
<xsd:schema +
|
||||
xmlns:xsd="http://www.w3.org/2001/XMLSchema"> +
|
||||
+
|
||||
@ -932,12 +958,24 @@ SELECT schema_to_xmlschema('testxmlschema', false, true, '');
|
||||
</xsd:restriction> +
|
||||
</xsd:simpleType> +
|
||||
+
|
||||
<xsd:simpleType name="TIME_WTZ"> +
|
||||
<xsd:restriction base="xsd:time"> +
|
||||
<xsd:pattern value="\p{Nd}{2}:\p{Nd}{2}:\p{Nd}{2}(.\p{Nd}+)?(\+|-)\p{Nd}{2}:\p{Nd}{2}"/> +
|
||||
</xsd:restriction> +
|
||||
</xsd:simpleType> +
|
||||
+
|
||||
<xsd:simpleType name="TIMESTAMP"> +
|
||||
<xsd:restriction base="xsd:dateTime"> +
|
||||
<xsd:pattern value="\p{Nd}{4}-\p{Nd}{2}-\p{Nd}{2}T\p{Nd}{2}:\p{Nd}{2}:\p{Nd}{2}(.\p{Nd}+)?"/> +
|
||||
</xsd:restriction> +
|
||||
</xsd:simpleType> +
|
||||
+
|
||||
<xsd:simpleType name="TIMESTAMP_WTZ"> +
|
||||
<xsd:restriction base="xsd:dateTime"> +
|
||||
<xsd:pattern value="\p{Nd}{4}-\p{Nd}{2}-\p{Nd}{2}T\p{Nd}{2}:\p{Nd}{2}:\p{Nd}{2}(.\p{Nd}+)?(\+|-)\p{Nd}{2}:\p{Nd}{2}"/>+
|
||||
</xsd:restriction> +
|
||||
</xsd:simpleType> +
|
||||
+
|
||||
<xsd:simpleType name="DATE"> +
|
||||
<xsd:restriction base="xsd:date"> +
|
||||
<xsd:pattern value="\p{Nd}{4}-\p{Nd}{2}-\p{Nd}{2}"/> +
|
||||
@ -977,7 +1015,7 @@ SELECT schema_to_xmlschema('testxmlschema', false, true, '');
|
||||
|
||||
SELECT schema_to_xmlschema('testxmlschema', true, false, '');
|
||||
schema_to_xmlschema
|
||||
---------------------------------------------------------------------------------------------------
|
||||
----------------------------------------------------------------------------------------------------------------------------
|
||||
<xsd:schema +
|
||||
xmlns:xsd="http://www.w3.org/2001/XMLSchema"> +
|
||||
+
|
||||
@ -1030,12 +1068,24 @@ SELECT schema_to_xmlschema('testxmlschema', true, false, '');
|
||||
</xsd:restriction> +
|
||||
</xsd:simpleType> +
|
||||
+
|
||||
<xsd:simpleType name="TIME_WTZ"> +
|
||||
<xsd:restriction base="xsd:time"> +
|
||||
<xsd:pattern value="\p{Nd}{2}:\p{Nd}{2}:\p{Nd}{2}(.\p{Nd}+)?(\+|-)\p{Nd}{2}:\p{Nd}{2}"/> +
|
||||
</xsd:restriction> +
|
||||
</xsd:simpleType> +
|
||||
+
|
||||
<xsd:simpleType name="TIMESTAMP"> +
|
||||
<xsd:restriction base="xsd:dateTime"> +
|
||||
<xsd:pattern value="\p{Nd}{4}-\p{Nd}{2}-\p{Nd}{2}T\p{Nd}{2}:\p{Nd}{2}:\p{Nd}{2}(.\p{Nd}+)?"/> +
|
||||
</xsd:restriction> +
|
||||
</xsd:simpleType> +
|
||||
+
|
||||
<xsd:simpleType name="TIMESTAMP_WTZ"> +
|
||||
<xsd:restriction base="xsd:dateTime"> +
|
||||
<xsd:pattern value="\p{Nd}{4}-\p{Nd}{2}-\p{Nd}{2}T\p{Nd}{2}:\p{Nd}{2}:\p{Nd}{2}(.\p{Nd}+)?(\+|-)\p{Nd}{2}:\p{Nd}{2}"/>+
|
||||
</xsd:restriction> +
|
||||
</xsd:simpleType> +
|
||||
+
|
||||
<xsd:simpleType name="DATE"> +
|
||||
<xsd:restriction base="xsd:date"> +
|
||||
<xsd:pattern value="\p{Nd}{4}-\p{Nd}{2}-\p{Nd}{2}"/> +
|
||||
@ -1075,7 +1125,7 @@ SELECT schema_to_xmlschema('testxmlschema', true, false, '');
|
||||
|
||||
SELECT schema_to_xml_and_xmlschema('testxmlschema', true, true, 'foo');
|
||||
schema_to_xml_and_xmlschema
|
||||
-------------------------------------------------------------------------------------------------------------------
|
||||
----------------------------------------------------------------------------------------------------------------------------
|
||||
<testxmlschema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="foo" xsi:schemaLocation="foo #"> +
|
||||
+
|
||||
<xsd:schema +
|
||||
@ -1132,12 +1182,24 @@ SELECT schema_to_xml_and_xmlschema('testxmlschema', true, true, 'foo');
|
||||
</xsd:restriction> +
|
||||
</xsd:simpleType> +
|
||||
+
|
||||
<xsd:simpleType name="TIME_WTZ"> +
|
||||
<xsd:restriction base="xsd:time"> +
|
||||
<xsd:pattern value="\p{Nd}{2}:\p{Nd}{2}:\p{Nd}{2}(.\p{Nd}+)?(\+|-)\p{Nd}{2}:\p{Nd}{2}"/> +
|
||||
</xsd:restriction> +
|
||||
</xsd:simpleType> +
|
||||
+
|
||||
<xsd:simpleType name="TIMESTAMP"> +
|
||||
<xsd:restriction base="xsd:dateTime"> +
|
||||
<xsd:pattern value="\p{Nd}{4}-\p{Nd}{2}-\p{Nd}{2}T\p{Nd}{2}:\p{Nd}{2}:\p{Nd}{2}(.\p{Nd}+)?"/> +
|
||||
</xsd:restriction> +
|
||||
</xsd:simpleType> +
|
||||
+
|
||||
<xsd:simpleType name="TIMESTAMP_WTZ"> +
|
||||
<xsd:restriction base="xsd:dateTime"> +
|
||||
<xsd:pattern value="\p{Nd}{4}-\p{Nd}{2}-\p{Nd}{2}T\p{Nd}{2}:\p{Nd}{2}:\p{Nd}{2}(.\p{Nd}+)?(\+|-)\p{Nd}{2}:\p{Nd}{2}"/>+
|
||||
</xsd:restriction> +
|
||||
</xsd:simpleType> +
|
||||
+
|
||||
<xsd:simpleType name="DATE"> +
|
||||
<xsd:restriction base="xsd:date"> +
|
||||
<xsd:pattern value="\p{Nd}{4}-\p{Nd}{2}-\p{Nd}{2}"/> +
|
||||
@ -1199,7 +1261,9 @@ SELECT schema_to_xml_and_xmlschema('testxmlschema', true, true, 'foo');
|
||||
<u>999</u> +
|
||||
<t>0</t> +
|
||||
<s>21:07:00</s> +
|
||||
<stz>21:11:00+05</stz> +
|
||||
<r>2009-06-08T21:07:30</r> +
|
||||
<rtz>2009-06-08T21:07:30-07:00</rtz> +
|
||||
<q>2009-06-08</q> +
|
||||
<p xsi:nil="true"/> +
|
||||
<o>ABC</o> +
|
||||
|
@ -2,9 +2,15 @@ CREATE SCHEMA testxmlschema;
|
||||
CREATE TABLE testxmlschema.test1 (a int, b text);
|
||||
INSERT INTO testxmlschema.test1 VALUES (1, 'one'), (2, 'two'), (-1, null);
|
||||
CREATE DOMAIN testxmldomain AS varchar;
|
||||
CREATE TABLE testxmlschema.test2 (z int, y varchar(500), x char(6), w numeric(9,2), v smallint, u bigint, t real, s time, r timestamp, q date, p xml, o testxmldomain, n bool, m bytea, aaa text);
|
||||
CREATE TABLE testxmlschema.test2 (z int, y varchar(500), x char(6),
|
||||
w numeric(9,2), v smallint, u bigint, t real,
|
||||
s time, stz timetz, r timestamp, rtz timestamptz, q date,
|
||||
p xml, o testxmldomain, n bool, m bytea, aaa text);
|
||||
ALTER TABLE testxmlschema.test2 DROP COLUMN aaa;
|
||||
INSERT INTO testxmlschema.test2 VALUES (55, 'abc', 'def', 98.6, 2, 999, 0, '21:07', '2009-06-08 21:07:30', '2009-06-08', NULL, 'ABC', true, 'XYZ');
|
||||
INSERT INTO testxmlschema.test2 VALUES (55, 'abc', 'def',
|
||||
98.6, 2, 999, 0,
|
||||
'21:07', '21:11 +05', '2009-06-08 21:07:30', '2009-06-08 21:07:30 -07', '2009-06-08',
|
||||
NULL, 'ABC', true, 'XYZ');
|
||||
SELECT table_to_xml('testxmlschema.test1', false, false, '');
|
||||
ERROR: unsupported XML feature
|
||||
DETAIL: This functionality requires the server to be built with libxml support.
|
||||
|
@ -3,9 +3,15 @@ CREATE SCHEMA testxmlschema;
|
||||
CREATE TABLE testxmlschema.test1 (a int, b text);
|
||||
INSERT INTO testxmlschema.test1 VALUES (1, 'one'), (2, 'two'), (-1, null);
|
||||
CREATE DOMAIN testxmldomain AS varchar;
|
||||
CREATE TABLE testxmlschema.test2 (z int, y varchar(500), x char(6), w numeric(9,2), v smallint, u bigint, t real, s time, r timestamp, q date, p xml, o testxmldomain, n bool, m bytea, aaa text);
|
||||
CREATE TABLE testxmlschema.test2 (z int, y varchar(500), x char(6),
|
||||
w numeric(9,2), v smallint, u bigint, t real,
|
||||
s time, stz timetz, r timestamp, rtz timestamptz, q date,
|
||||
p xml, o testxmldomain, n bool, m bytea, aaa text);
|
||||
ALTER TABLE testxmlschema.test2 DROP COLUMN aaa;
|
||||
INSERT INTO testxmlschema.test2 VALUES (55, 'abc', 'def', 98.6, 2, 999, 0, '21:07', '2009-06-08 21:07:30', '2009-06-08', NULL, 'ABC', true, 'XYZ');
|
||||
INSERT INTO testxmlschema.test2 VALUES (55, 'abc', 'def',
|
||||
98.6, 2, 999, 0,
|
||||
'21:07', '21:11 +05', '2009-06-08 21:07:30', '2009-06-08 21:07:30 -07', '2009-06-08',
|
||||
NULL, 'ABC', true, 'XYZ');
|
||||
|
||||
SELECT table_to_xml('testxmlschema.test1', false, false, '');
|
||||
SELECT table_to_xml('testxmlschema.test1', true, false, 'foo');
|
||||
|
Loading…
x
Reference in New Issue
Block a user