mirror of
https://github.com/postgres/postgres.git
synced 2025-11-29 23:43:17 +03:00
Add support for xmlval IS DOCUMENT expression.
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
* ruleutils.c - Functions to convert stored expressions/querytrees
|
||||
* back to source text
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.241 2007/01/09 02:14:14 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.242 2007/01/14 13:11:54 petere Exp $
|
||||
**********************************************************************/
|
||||
|
||||
#include "postgres.h"
|
||||
@@ -3847,6 +3847,8 @@ get_rule_expr(Node *node, deparse_context *context,
|
||||
case IS_XMLROOT:
|
||||
appendStringInfoString(buf, "XMLROOT(");
|
||||
break;
|
||||
case IS_DOCUMENT:
|
||||
break;
|
||||
}
|
||||
if (xexpr->name)
|
||||
{
|
||||
@@ -3888,6 +3890,7 @@ get_rule_expr(Node *node, deparse_context *context,
|
||||
case IS_XMLELEMENT:
|
||||
case IS_XMLFOREST:
|
||||
case IS_XMLPI:
|
||||
case IS_DOCUMENT:
|
||||
/* no extra decoration needed */
|
||||
get_rule_expr((Node *) xexpr->args, context, true);
|
||||
break;
|
||||
@@ -3943,7 +3946,10 @@ get_rule_expr(Node *node, deparse_context *context,
|
||||
}
|
||||
|
||||
}
|
||||
appendStringInfoChar(buf, ')');
|
||||
if (xexpr->op == IS_DOCUMENT)
|
||||
appendStringInfoString(buf, " IS DOCUMENT");
|
||||
else
|
||||
appendStringInfoChar(buf, ')');
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.16 2007/01/12 21:47:26 petere Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.17 2007/01/14 13:11:54 petere Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -515,6 +515,50 @@ xmlvalidate(PG_FUNCTION_ARGS)
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
xml_is_document(xmltype *arg)
|
||||
{
|
||||
#ifdef USE_LIBXML
|
||||
bool result;
|
||||
xmlDocPtr doc = NULL;
|
||||
MemoryContext ccxt = CurrentMemoryContext;
|
||||
|
||||
PG_TRY();
|
||||
{
|
||||
doc = xml_parse((text *) arg, true, true);
|
||||
result = true;
|
||||
}
|
||||
PG_CATCH();
|
||||
{
|
||||
ErrorData *errdata;
|
||||
MemoryContext ecxt;
|
||||
|
||||
ecxt = MemoryContextSwitchTo(ccxt);
|
||||
errdata = CopyErrorData();
|
||||
if (errdata->sqlerrcode == ERRCODE_INVALID_XML_DOCUMENT)
|
||||
{
|
||||
FlushErrorState();
|
||||
result = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
MemoryContextSwitchTo(ecxt);
|
||||
PG_RE_THROW();
|
||||
}
|
||||
}
|
||||
PG_END_TRY();
|
||||
|
||||
if (doc)
|
||||
xmlFreeDoc(doc);
|
||||
|
||||
return result;
|
||||
#else /* not USE_LIBXML */
|
||||
NO_XML_SUPPORT();
|
||||
return false;
|
||||
#endif /* not USE_LIBXML */
|
||||
}
|
||||
|
||||
|
||||
#ifdef USE_LIBXML
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user