Commit 77d67a4a authored by Peter Eisentraut's avatar Peter Eisentraut

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().
parent 84bb600b
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/executor/execQual.c,v 1.245 2009/04/05 20:32:06 tgl Exp $ * $PostgreSQL: pgsql/src/backend/executor/execQual.c,v 1.246 2009/04/08 21:51:38 petere Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -4671,27 +4671,16 @@ ExecInitExpr(Expr *node, PlanState *parent) ...@@ -4671,27 +4671,16 @@ ExecInitExpr(Expr *node, PlanState *parent)
XmlExprState *xstate = makeNode(XmlExprState); XmlExprState *xstate = makeNode(XmlExprState);
List *outlist; List *outlist;
ListCell *arg; ListCell *arg;
int i;
xstate->xprstate.evalfunc = (ExprStateEvalFunc) ExecEvalXml; xstate->xprstate.evalfunc = (ExprStateEvalFunc) ExecEvalXml;
xstate->named_outfuncs = (FmgrInfo *)
palloc0(list_length(xexpr->named_args) * sizeof(FmgrInfo));
outlist = NIL; outlist = NIL;
i = 0;
foreach(arg, xexpr->named_args) foreach(arg, xexpr->named_args)
{ {
Expr *e = (Expr *) lfirst(arg); Expr *e = (Expr *) lfirst(arg);
ExprState *estate; ExprState *estate;
Oid typOutFunc;
bool typIsVarlena;
estate = ExecInitExpr(e, parent); estate = ExecInitExpr(e, parent);
outlist = lappend(outlist, estate); outlist = lappend(outlist, estate);
getTypeOutputInfo(exprType((Node *) e),
&typOutFunc, &typIsVarlena);
fmgr_info(typOutFunc, &xstate->named_outfuncs[i]);
i++;
} }
xstate->named_args = outlist; xstate->named_args = outlist;
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.85 2009/03/27 18:56:57 tgl Exp $ * $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.86 2009/04/08 21:51:38 petere Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -572,7 +572,7 @@ xmlelement(XmlExprState *xmlExpr, ExprContext *econtext) ...@@ -572,7 +572,7 @@ xmlelement(XmlExprState *xmlExpr, ExprContext *econtext)
if (isnull) if (isnull)
str = NULL; str = NULL;
else else
str = OutputFunctionCall(&xmlExpr->named_outfuncs[i], value); str = map_sql_value_to_xml_value(value, exprType((Node *) e->expr));
named_arg_strings = lappend(named_arg_strings, str); named_arg_strings = lappend(named_arg_strings, str);
i++; i++;
} }
...@@ -609,12 +609,9 @@ xmlelement(XmlExprState *xmlExpr, ExprContext *econtext) ...@@ -609,12 +609,9 @@ xmlelement(XmlExprState *xmlExpr, ExprContext *econtext)
char *argname = strVal(lfirst(narg)); char *argname = strVal(lfirst(narg));
if (str) if (str)
{
xmlTextWriterWriteAttribute(writer, xmlTextWriterWriteAttribute(writer,
(xmlChar *) argname, (xmlChar *) argname,
(xmlChar *) str); (xmlChar *) str);
pfree(str);
}
} }
foreach(arg, arg_strings) foreach(arg, arg_strings)
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/nodes/execnodes.h,v 1.203 2009/04/02 22:39:30 tgl Exp $ * $PostgreSQL: pgsql/src/include/nodes/execnodes.h,v 1.204 2009/04/08 21:51:38 petere Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -847,7 +847,6 @@ typedef struct XmlExprState ...@@ -847,7 +847,6 @@ typedef struct XmlExprState
{ {
ExprState xprstate; ExprState xprstate;
List *named_args; /* ExprStates for named arguments */ List *named_args; /* ExprStates for named arguments */
FmgrInfo *named_outfuncs; /* array of output fns for named arguments */
List *args; /* ExprStates for other arguments */ List *args; /* ExprStates for other arguments */
} XmlExprState; } XmlExprState;
......
...@@ -173,6 +173,21 @@ SELECT xmlelement(name foo, bytea 'bar'); ...@@ -173,6 +173,21 @@ SELECT xmlelement(name foo, bytea 'bar');
<foo>626172</foo> <foo>626172</foo>
(1 row) (1 row)
SELECT xmlelement(name foo, xmlattributes(true as bar));
xmlelement
-------------------
<foo bar="true"/>
(1 row)
SELECT xmlelement(name foo, xmlattributes('2009-04-09 00:24:37'::timestamp as bar));
xmlelement
----------------------------------
<foo bar="2009-04-09T00:24:37"/>
(1 row)
SELECT xmlelement(name foo, xmlattributes('infinity'::timestamp as bar));
ERROR: timestamp out of range
DETAIL: XML does not support infinite timestamp values.
SELECT xmlparse(content 'abc'); SELECT xmlparse(content 'abc');
xmlparse xmlparse
---------- ----------
......
...@@ -148,6 +148,18 @@ SELECT xmlelement(name foo, bytea 'bar'); ...@@ -148,6 +148,18 @@ SELECT xmlelement(name foo, bytea 'bar');
ERROR: unsupported XML feature ERROR: unsupported XML feature
DETAIL: This functionality requires the server to be built with libxml support. DETAIL: This functionality requires the server to be built with libxml support.
HINT: You need to rebuild PostgreSQL using --with-libxml. HINT: You need to rebuild PostgreSQL using --with-libxml.
SELECT xmlelement(name foo, xmlattributes(true as bar));
ERROR: unsupported XML feature
DETAIL: This functionality requires the server to be built with libxml support.
HINT: You need to rebuild PostgreSQL using --with-libxml.
SELECT xmlelement(name foo, xmlattributes('2009-04-09 00:24:37'::timestamp as bar));
ERROR: unsupported XML feature
DETAIL: This functionality requires the server to be built with libxml support.
HINT: You need to rebuild PostgreSQL using --with-libxml.
SELECT xmlelement(name foo, xmlattributes('infinity'::timestamp as bar));
ERROR: unsupported XML feature
DETAIL: This functionality requires the server to be built with libxml support.
HINT: You need to rebuild PostgreSQL using --with-libxml.
SELECT xmlparse(content 'abc'); SELECT xmlparse(content 'abc');
ERROR: unsupported XML feature ERROR: unsupported XML feature
DETAIL: This functionality requires the server to be built with libxml support. DETAIL: This functionality requires the server to be built with libxml support.
......
...@@ -54,6 +54,10 @@ SELECT xmlelement(name foo, bytea 'bar'); ...@@ -54,6 +54,10 @@ SELECT xmlelement(name foo, bytea 'bar');
SET xmlbinary TO hex; SET xmlbinary TO hex;
SELECT xmlelement(name foo, bytea 'bar'); SELECT xmlelement(name foo, bytea 'bar');
SELECT xmlelement(name foo, xmlattributes(true as bar));
SELECT xmlelement(name foo, xmlattributes('2009-04-09 00:24:37'::timestamp as bar));
SELECT xmlelement(name foo, xmlattributes('infinity'::timestamp as bar));
SELECT xmlparse(content 'abc'); SELECT xmlparse(content 'abc');
SELECT xmlparse(content '<abc>x</abc>'); SELECT xmlparse(content '<abc>x</abc>');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment