summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Eisentraut2009-04-08 21:51:38 +0000
committerPeter Eisentraut2009-04-08 21:51:38 +0000
commit2c61473757bd6ad65dedefb0c5b38435e6103fe1 (patch)
tree67e674aed8819fff6a12fba89cfacae3afc55d83
parent1078f7e6275b094c80093f3f03e036d486c675e4 (diff)
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().
-rw-r--r--src/backend/executor/execQual.c11
-rw-r--r--src/backend/utils/adt/xml.c5
-rw-r--r--src/include/nodes/execnodes.h1
-rw-r--r--src/test/regress/expected/xml.out15
-rw-r--r--src/test/regress/expected/xml_1.out12
-rw-r--r--src/test/regress/sql/xml.sql4
6 files changed, 32 insertions, 16 deletions
diff --git a/src/backend/executor/execQual.c b/src/backend/executor/execQual.c
index 1fac16212a..c3e7e24531 100644
--- a/src/backend/executor/execQual.c
+++ b/src/backend/executor/execQual.c
@@ -4671,27 +4671,16 @@ ExecInitExpr(Expr *node, PlanState *parent)
XmlExprState *xstate = makeNode(XmlExprState);
List *outlist;
ListCell *arg;
- int i;
xstate->xprstate.evalfunc = (ExprStateEvalFunc) ExecEvalXml;
- xstate->named_outfuncs = (FmgrInfo *)
- palloc0(list_length(xexpr->named_args) * sizeof(FmgrInfo));
outlist = NIL;
- i = 0;
foreach(arg, xexpr->named_args)
{
Expr *e = (Expr *) lfirst(arg);
ExprState *estate;
- Oid typOutFunc;
- bool typIsVarlena;
estate = ExecInitExpr(e, parent);
outlist = lappend(outlist, estate);
-
- getTypeOutputInfo(exprType((Node *) e),
- &typOutFunc, &typIsVarlena);
- fmgr_info(typOutFunc, &xstate->named_outfuncs[i]);
- i++;
}
xstate->named_args = outlist;
diff --git a/src/backend/utils/adt/xml.c b/src/backend/utils/adt/xml.c
index 2b36d1c23f..d929832fe6 100644
--- a/src/backend/utils/adt/xml.c
+++ b/src/backend/utils/adt/xml.c
@@ -572,7 +572,7 @@ xmlelement(XmlExprState *xmlExpr, ExprContext *econtext)
if (isnull)
str = NULL;
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);
i++;
}
@@ -609,12 +609,9 @@ xmlelement(XmlExprState *xmlExpr, ExprContext *econtext)
char *argname = strVal(lfirst(narg));
if (str)
- {
xmlTextWriterWriteAttribute(writer,
(xmlChar *) argname,
(xmlChar *) str);
- pfree(str);
- }
}
foreach(arg, arg_strings)
diff --git a/src/include/nodes/execnodes.h b/src/include/nodes/execnodes.h
index e254f7437c..ae4f1fbb3a 100644
--- a/src/include/nodes/execnodes.h
+++ b/src/include/nodes/execnodes.h
@@ -847,7 +847,6 @@ typedef struct XmlExprState
{
ExprState xprstate;
List *named_args; /* ExprStates for named arguments */
- FmgrInfo *named_outfuncs; /* array of output fns for named arguments */
List *args; /* ExprStates for other arguments */
} XmlExprState;
diff --git a/src/test/regress/expected/xml.out b/src/test/regress/expected/xml.out
index f0c4d0a05c..30b332aecc 100644
--- a/src/test/regress/expected/xml.out
+++ b/src/test/regress/expected/xml.out
@@ -173,6 +173,21 @@ SELECT xmlelement(name foo, bytea 'bar');
<foo>626172</foo>
(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');
xmlparse
----------
diff --git a/src/test/regress/expected/xml_1.out b/src/test/regress/expected/xml_1.out
index bfa3d612c5..c8eb1e425e 100644
--- a/src/test/regress/expected/xml_1.out
+++ b/src/test/regress/expected/xml_1.out
@@ -148,6 +148,18 @@ SELECT xmlelement(name foo, bytea '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(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');
ERROR: unsupported XML feature
DETAIL: This functionality requires the server to be built with libxml support.
diff --git a/src/test/regress/sql/xml.sql b/src/test/regress/sql/xml.sql
index edf639b8c5..50550aaa35 100644
--- a/src/test/regress/sql/xml.sql
+++ b/src/test/regress/sql/xml.sql
@@ -54,6 +54,10 @@ SELECT xmlelement(name foo, bytea 'bar');
SET xmlbinary TO hex;
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>x</abc>');