git.postgresql.org Git - postgresql.git/commitdiff

git projects / postgresql.git / commitdiff
? search:
summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 19f9376)
Prevent duplicate attribute names in XMLELEMENT.
Mon, 8 Jan 2007 23:41:57 +0000 (23:41 +0000)
Mon, 8 Jan 2007 23:41:57 +0000 (23:41 +0000)

diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index c15858fc7a14624acb7b80de478739db62e434bf..033dd6c75cf3374ec82cf4aa4d0a4ba219a51200 100644 (file)
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/parser/parse_expr.c,v 1.204 2007年01月05日 22:19:34 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/parser/parse_expr.c,v 1.205 2007年01月08日 23:41:56 petere Exp $
*
*-------------------------------------------------------------------------
*/
@@ -1415,8 +1415,8 @@ transformXmlExpr(ParseState *pstate, XmlExpr *x)
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
x->op == IS_XMLELEMENT
- ? errmsg("unnamed attribute value must be a column reference")
- : errmsg("unnamed element value must be a column reference")));
+ ? errmsg("unnamed XML attribute value must be a column reference")
+ : errmsg("unnamed XML element value must be a column reference")));
argname = NULL; /* keep compiler quiet */
}
@@ -1424,6 +1424,22 @@ transformXmlExpr(ParseState *pstate, XmlExpr *x)
newx->arg_names = lappend(newx->arg_names, makeString(argname));
}
+ if (x->op == IS_XMLELEMENT)
+ {
+ foreach(lc, newx->arg_names)
+ {
+ ListCell *lc2;
+
+ for_each_cell(lc2, lnext(lc))
+ {
+ if (strcmp(strVal(lfirst(lc)), strVal(lfirst(lc2))) == 0)
+ ereport(ERROR,
+ (errcode(ERRCODE_SYNTAX_ERROR),
+ errmsg("XML attribute name \"%s\" appears more than once", strVal(lfirst(lc)))));
+ }
+ }
+ }
+
/* The other arguments are of varying types depending on the function */
newx->args = NIL;
i = 0;
diff --git a/src/test/regress/expected/xml.out b/src/test/regress/expected/xml.out
index c0ec868bf8998e2c05d9d89d0000ee3803f091ed..4179233e99938414e088ce55fa1dc0d0e72a5a0d 100644 (file)
--- a/src/test/regress/expected/xml.out
+++ b/src/test/regress/expected/xml.out
@@ -65,7 +65,7 @@ SELECT xmlelement(name element,
SELECT xmlelement(name element,
xmlattributes ('unnamed and wrong'));
-ERROR: unnamed attribute value must be a column reference
+ERROR: unnamed XML attribute value must be a column reference
SELECT xmlelement(name element, xmlelement(name nested, 'stuff'));
xmlelement
-------------------------------------------
@@ -85,6 +85,8 @@ SELECT xmlelement(name employee, xmlforest(name, age, salary as pay)) FROM emp;
SELECT xmlelement(name wrong, 37);
ERROR: argument of XMLELEMENT must be type xml, not type integer
+SELECT xmlelement(name duplicate, xmlattributes(1 as a, 2 as b, 3 as a));
+ERROR: XML attribute name "a" appears more than once
SELECT xmlparse(content 'abc');
xmlparse
----------
diff --git a/src/test/regress/expected/xml_1.out b/src/test/regress/expected/xml_1.out
index 5a1a6ac03199002cae9025f4df9c73767b71c5ee..8ef963b8e9db4a4a2f8dab0ed38e63dba59f57cf 100644 (file)
--- a/src/test/regress/expected/xml_1.out
+++ b/src/test/regress/expected/xml_1.out
@@ -46,6 +46,8 @@ SELECT xmlelement(name employee, xmlforest(name, age, salary as pay)) FROM emp;
ERROR: no XML support in this installation
SELECT xmlelement(name wrong, 37);
ERROR: no XML support in this installation
+SELECT xmlelement(name duplicate, xmlattributes(1 as a, 2 as b, 3 as a));
+ERROR: no XML support in this installation
SELECT xmlparse(content 'abc');
ERROR: no XML support in this installation
SELECT xmlparse(content '<abc>x</abc>');
diff --git a/src/test/regress/sql/xml.sql b/src/test/regress/sql/xml.sql
index ae7d633c1c4c15f0bdeeefcb6d1e7a86c63bb5ad..d3a1e6104bb87126fe74e52cb930c33918b60efa 100644 (file)
--- a/src/test/regress/sql/xml.sql
+++ b/src/test/regress/sql/xml.sql
@@ -38,6 +38,7 @@ SELECT xmlelement(name element, xmlelement(name nested, 'stuff'));
SELECT xmlelement(name employee, xmlforest(name, age, salary as pay)) FROM emp;
SELECT xmlelement(name wrong, 37);
+SELECT xmlelement(name duplicate, xmlattributes(1 as a, 2 as b, 3 as a));
SELECT xmlparse(content 'abc');
This is the main PostgreSQL git repository.
RSS Atom

AltStyle によって変換されたページ (->オリジナル) /