mirror of
https://github.com/postgres/postgres.git
synced 2025-04-27 22:56:53 +03:00
Prevent duplicate attribute names in XMLELEMENT.
This commit is contained in:
parent
19f9376bf4
commit
3a32ba2f3f
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* 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,
|
ereport(ERROR,
|
||||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||||
x->op == IS_XMLELEMENT
|
x->op == IS_XMLELEMENT
|
||||||
? errmsg("unnamed attribute value must be a column reference")
|
? errmsg("unnamed XML attribute value must be a column reference")
|
||||||
: errmsg("unnamed element value must be a column reference")));
|
: errmsg("unnamed XML element value must be a column reference")));
|
||||||
argname = NULL; /* keep compiler quiet */
|
argname = NULL; /* keep compiler quiet */
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1424,6 +1424,22 @@ transformXmlExpr(ParseState *pstate, XmlExpr *x)
|
|||||||
newx->arg_names = lappend(newx->arg_names, makeString(argname));
|
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 */
|
/* The other arguments are of varying types depending on the function */
|
||||||
newx->args = NIL;
|
newx->args = NIL;
|
||||||
i = 0;
|
i = 0;
|
||||||
|
@ -65,7 +65,7 @@ SELECT xmlelement(name element,
|
|||||||
|
|
||||||
SELECT xmlelement(name element,
|
SELECT xmlelement(name element,
|
||||||
xmlattributes ('unnamed and wrong'));
|
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'));
|
SELECT xmlelement(name element, xmlelement(name nested, 'stuff'));
|
||||||
xmlelement
|
xmlelement
|
||||||
-------------------------------------------
|
-------------------------------------------
|
||||||
@ -85,6 +85,8 @@ SELECT xmlelement(name employee, xmlforest(name, age, salary as pay)) FROM emp;
|
|||||||
|
|
||||||
SELECT xmlelement(name wrong, 37);
|
SELECT xmlelement(name wrong, 37);
|
||||||
ERROR: argument of XMLELEMENT must be type xml, not type integer
|
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');
|
SELECT xmlparse(content 'abc');
|
||||||
xmlparse
|
xmlparse
|
||||||
----------
|
----------
|
||||||
|
@ -46,6 +46,8 @@ SELECT xmlelement(name employee, xmlforest(name, age, salary as pay)) FROM emp;
|
|||||||
ERROR: no XML support in this installation
|
ERROR: no XML support in this installation
|
||||||
SELECT xmlelement(name wrong, 37);
|
SELECT xmlelement(name wrong, 37);
|
||||||
ERROR: no XML support in this installation
|
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');
|
SELECT xmlparse(content 'abc');
|
||||||
ERROR: no XML support in this installation
|
ERROR: no XML support in this installation
|
||||||
SELECT xmlparse(content '<abc>x</abc>');
|
SELECT xmlparse(content '<abc>x</abc>');
|
||||||
|
@ -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 employee, xmlforest(name, age, salary as pay)) FROM emp;
|
||||||
|
|
||||||
SELECT xmlelement(name wrong, 37);
|
SELECT xmlelement(name wrong, 37);
|
||||||
|
SELECT xmlelement(name duplicate, xmlattributes(1 as a, 2 as b, 3 as a));
|
||||||
|
|
||||||
|
|
||||||
SELECT xmlparse(content 'abc');
|
SELECT xmlparse(content 'abc');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user