From ec020e1ceb94d0ceb3c0eee8c39cd197be7bb3cb Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Sat, 3 Feb 2007 14:06:56 +0000 Subject: Implement XMLSERIALIZE for real. Analogously, make the xml to text cast observe the xmloption. Reorganize the representation of the XML option in the parse tree and the API to make it easier to manage and understand. Add regression tests for parsing back XML expressions. --- src/backend/utils/adt/ruleutils.c | 52 +++++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 16 deletions(-) (limited to 'src/backend/utils/adt/ruleutils.c') diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c index 668266d1c4d..3cd317361f4 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.247 2007/01/30 02:39:27 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.248 2007/02/03 14:06:54 petere Exp $ * *------------------------------------------------------------------------- */ @@ -3856,9 +3856,19 @@ get_rule_expr(Node *node, deparse_context *context, case IS_XMLROOT: appendStringInfoString(buf, "XMLROOT("); break; + case IS_XMLSERIALIZE: + appendStringInfoString(buf, "XMLSERIALIZE("); + break; case IS_DOCUMENT: break; } + if (xexpr->op == IS_XMLPARSE || xexpr->op == IS_XMLSERIALIZE) + { + if (xexpr->xmloption == XMLOPTION_DOCUMENT) + appendStringInfoString(buf, "DOCUMENT "); + else + appendStringInfoString(buf, "CONTENT "); + } if (xexpr->name) { appendStringInfo(buf, "NAME %s", @@ -3899,24 +3909,17 @@ get_rule_expr(Node *node, deparse_context *context, case IS_XMLELEMENT: case IS_XMLFOREST: case IS_XMLPI: + case IS_XMLSERIALIZE: /* no extra decoration needed */ get_rule_expr((Node *) xexpr->args, context, true); break; case IS_XMLPARSE: - Assert(list_length(xexpr->args) == 3); - - con = (Const *) lsecond(xexpr->args); - Assert(IsA(con, Const)); - Assert(!con->constisnull); - if (DatumGetBool(con->constvalue)) - appendStringInfoString(buf, "DOCUMENT "); - else - appendStringInfoString(buf, "CONTENT "); + Assert(list_length(xexpr->args) == 2); get_rule_expr((Node *) linitial(xexpr->args), context, true); - con = (Const *) lthird(xexpr->args); + con = (Const *) lsecond(xexpr->args); Assert(IsA(con, Const)); Assert(!con->constisnull); if (DatumGetBool(con->constvalue)) @@ -3944,12 +3947,26 @@ get_rule_expr(Node *node, deparse_context *context, Assert(IsA(con, Const)); if (con->constisnull) /* suppress STANDALONE NO VALUE */ ; - else if (DatumGetBool(con->constvalue)) - appendStringInfoString(buf, - ", STANDALONE YES"); else - appendStringInfoString(buf, - ", STANDALONE NO"); + { + switch (DatumGetInt32(con->constvalue)) + { + case XML_STANDALONE_YES: + appendStringInfoString(buf, + ", STANDALONE YES"); + break; + case XML_STANDALONE_NO: + appendStringInfoString(buf, + ", STANDALONE NO"); + break; + case XML_STANDALONE_NO_VALUE: + appendStringInfoString(buf, + ", STANDALONE NO VALUE"); + break; + default: + break; + } + } break; case IS_DOCUMENT: get_rule_expr_paren((Node *) xexpr->args, context, false, node); @@ -3957,6 +3974,9 @@ get_rule_expr(Node *node, deparse_context *context, } } + if (xexpr->op == IS_XMLSERIALIZE) + appendStringInfo(buf, " AS %s", format_type_with_typemod(xexpr->type, + xexpr->typmod)); if (xexpr->op == IS_DOCUMENT) appendStringInfoString(buf, " IS DOCUMENT"); else -- cgit v1.2.3