Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 77d67a4

Browse files
committed
XMLATTRIBUTES() should send the attribute values through
map_sql_value_to_xml_value() instead of directly through the data type output function. This is per SQL standard, and consistent with XMLELEMENT().
1 parent 84bb600 commit 77d67a4

File tree

6 files changed

+35
-19
lines changed

6 files changed

+35
-19
lines changed

src/backend/executor/execQual.c

+1-12
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/executor/execQual.c,v 1.245 2009/04/05 20:32:06 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/executor/execQual.c,v 1.246 2009/04/08 21:51:38 petere Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -4671,27 +4671,16 @@ ExecInitExpr(Expr *node, PlanState *parent)
46714671
XmlExprState *xstate = makeNode(XmlExprState);
46724672
List *outlist;
46734673
ListCell *arg;
4674-
int i;
46754674

46764675
xstate->xprstate.evalfunc = (ExprStateEvalFunc) ExecEvalXml;
4677-
xstate->named_outfuncs = (FmgrInfo *)
4678-
palloc0(list_length(xexpr->named_args) * sizeof(FmgrInfo));
46794676
outlist = NIL;
4680-
i = 0;
46814677
foreach(arg, xexpr->named_args)
46824678
{
46834679
Expr *e = (Expr *) lfirst(arg);
46844680
ExprState *estate;
4685-
Oid typOutFunc;
4686-
bool typIsVarlena;
46874681

46884682
estate = ExecInitExpr(e, parent);
46894683
outlist = lappend(outlist, estate);
4690-
4691-
getTypeOutputInfo(exprType((Node *) e),
4692-
&typOutFunc, &typIsVarlena);
4693-
fmgr_info(typOutFunc, &xstate->named_outfuncs[i]);
4694-
i++;
46954684
}
46964685
xstate->named_args = outlist;
46974686

src/backend/utils/adt/xml.c

+2-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.85 2009/03/27 18:56:57 tgl Exp $
10+
* $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.86 2009/04/08 21:51:38 petere Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -572,7 +572,7 @@ xmlelement(XmlExprState *xmlExpr, ExprContext *econtext)
572572
if (isnull)
573573
str = NULL;
574574
else
575-
str = OutputFunctionCall(&xmlExpr->named_outfuncs[i], value);
575+
str = map_sql_value_to_xml_value(value, exprType((Node *) e->expr));
576576
named_arg_strings = lappend(named_arg_strings, str);
577577
i++;
578578
}
@@ -609,12 +609,9 @@ xmlelement(XmlExprState *xmlExpr, ExprContext *econtext)
609609
char *argname = strVal(lfirst(narg));
610610

611611
if (str)
612-
{
613612
xmlTextWriterWriteAttribute(writer,
614613
(xmlChar *) argname,
615614
(xmlChar *) str);
616-
pfree(str);
617-
}
618615
}
619616

620617
foreach(arg, arg_strings)

src/include/nodes/execnodes.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/nodes/execnodes.h,v 1.203 2009/04/02 22:39:30 tgl Exp $
10+
* $PostgreSQL: pgsql/src/include/nodes/execnodes.h,v 1.204 2009/04/08 21:51:38 petere Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -847,7 +847,6 @@ typedef struct XmlExprState
847847
{
848848
ExprState xprstate;
849849
List *named_args; /* ExprStates for named arguments */
850-
FmgrInfo *named_outfuncs; /* array of output fns for named arguments */
851850
List *args; /* ExprStates for other arguments */
852851
} XmlExprState;
853852

src/test/regress/expected/xml.out

+15
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,21 @@ SELECT xmlelement(name foo, bytea 'bar');
173173
<foo>626172</foo>
174174
(1 row)
175175

176+
SELECT xmlelement(name foo, xmlattributes(true as bar));
177+
xmlelement
178+
-------------------
179+
<foo bar="true"/>
180+
(1 row)
181+
182+
SELECT xmlelement(name foo, xmlattributes('2009-04-09 00:24:37'::timestamp as bar));
183+
xmlelement
184+
----------------------------------
185+
<foo bar="2009-04-09T00:24:37"/>
186+
(1 row)
187+
188+
SELECT xmlelement(name foo, xmlattributes('infinity'::timestamp as bar));
189+
ERROR: timestamp out of range
190+
DETAIL: XML does not support infinite timestamp values.
176191
SELECT xmlparse(content 'abc');
177192
xmlparse
178193
----------

src/test/regress/expected/xml_1.out

+12
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,18 @@ SELECT xmlelement(name foo, bytea 'bar');
148148
ERROR: unsupported XML feature
149149
DETAIL: This functionality requires the server to be built with libxml support.
150150
HINT: You need to rebuild PostgreSQL using --with-libxml.
151+
SELECT xmlelement(name foo, xmlattributes(true as bar));
152+
ERROR: unsupported XML feature
153+
DETAIL: This functionality requires the server to be built with libxml support.
154+
HINT: You need to rebuild PostgreSQL using --with-libxml.
155+
SELECT xmlelement(name foo, xmlattributes('2009-04-09 00:24:37'::timestamp as bar));
156+
ERROR: unsupported XML feature
157+
DETAIL: This functionality requires the server to be built with libxml support.
158+
HINT: You need to rebuild PostgreSQL using --with-libxml.
159+
SELECT xmlelement(name foo, xmlattributes('infinity'::timestamp as bar));
160+
ERROR: unsupported XML feature
161+
DETAIL: This functionality requires the server to be built with libxml support.
162+
HINT: You need to rebuild PostgreSQL using --with-libxml.
151163
SELECT xmlparse(content 'abc');
152164
ERROR: unsupported XML feature
153165
DETAIL: This functionality requires the server to be built with libxml support.

src/test/regress/sql/xml.sql

+4
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ SELECT xmlelement(name foo, bytea 'bar');
5454
SET xmlbinary TO hex;
5555
SELECT xmlelement(name foo, bytea 'bar');
5656

57+
SELECT xmlelement(name foo, xmlattributes(true as bar));
58+
SELECT xmlelement(name foo, xmlattributes('2009-04-09 00:24:37'::timestamp as bar));
59+
SELECT xmlelement(name foo, xmlattributes('infinity'::timestamp as bar));
60+
5761

5862
SELECT xmlparse(content 'abc');
5963
SELECT xmlparse(content '<abc>x</abc>');

0 commit comments

Comments
 (0)