]> granicus.if.org Git - postgresql/commitdiff
XMLATTRIBUTES() should send the attribute values through
authorPeter Eisentraut <peter_e@gmx.net>
Wed, 8 Apr 2009 21:51:38 +0000 (21:51 +0000)
committerPeter Eisentraut <peter_e@gmx.net>
Wed, 8 Apr 2009 21:51:38 +0000 (21:51 +0000)
map_sql_value_to_xml_value() instead of directly through the data type output
function.  This is per SQL standard, and consistent with XMLELEMENT().

src/backend/executor/execQual.c
src/backend/utils/adt/xml.c
src/include/nodes/execnodes.h
src/test/regress/expected/xml.out
src/test/regress/expected/xml_1.out
src/test/regress/sql/xml.sql

index b831aa530fad1f6a20ddc70e1f8d197be9496be4..d9cbb1d763abb17e53a13f35fe13d4e208af0acf 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * 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)
                                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;
 
index d7264eb156e9ff86cd85611d2d6094f129b0928b..5cb761773d921e3069cb1131eab773b86cebc0e5 100644 (file)
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
  * 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)
                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)
index cb293a0be554cd095a54ce122051ff284ab31a92..ad80018bfbacc216a01cd1c65a3290fb9cdf335e 100644 (file)
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
  * 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
 {
        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;
 
index f0c4d0a05c80f5fb8f51e40b105c96545bc6eb9c..30b332aeccafd0e3de01a9eea35519c29f098323 100644 (file)
@@ -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 
 ----------
index bfa3d612c5081e27f0ab25e401f56df14335b5b8..c8eb1e425e2c21fde0daba13c4cdd68cd2ef2cab 100644 (file)
@@ -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.
index edf639b8c53ffed4e1cd98a3c765ed1b711c1369..50550aaa3583baaa572c1bec27afa150fd7fc720 100644 (file)
@@ -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>');