diff options
author | Peter Eisentraut <peter_e@gmx.net> | 2006-12-28 14:28:36 +0000 |
---|---|---|
committer | Peter Eisentraut <peter_e@gmx.net> | 2006-12-28 14:28:36 +0000 |
commit | ad1425ae4346f599fc2420c00800a3748fed1259 (patch) | |
tree | 610fb9dc1f930d9cb94426f9988516a19870648e /src/backend/utils/adt/xml.c | |
parent | d9e1c97feb47a6f61707282133c4546fb682a5a8 (diff) | |
download | postgresql-ad1425ae4346f599fc2420c00800a3748fed1259.tar.gz postgresql-ad1425ae4346f599fc2420c00800a3748fed1259.zip |
Add send and recv functions for xml type.
Diffstat (limited to 'src/backend/utils/adt/xml.c')
-rw-r--r-- | src/backend/utils/adt/xml.c | 48 |
1 files changed, 45 insertions, 3 deletions
diff --git a/src/backend/utils/adt/xml.c b/src/backend/utils/adt/xml.c index 83704f6c794..6cde8d6aa49 100644 --- a/src/backend/utils/adt/xml.c +++ b/src/backend/utils/adt/xml.c @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.6 2006/12/28 03:17:38 petere Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.7 2006/12/28 14:28:36 petere Exp $ * *------------------------------------------------------------------------- */ @@ -34,6 +34,7 @@ #endif /* USE_LIBXML */ #include "fmgr.h" +#include "libpq/pqformat.h" #include "mb/pg_wchar.h" #include "nodes/execnodes.h" #include "utils/builtins.h" @@ -83,8 +84,7 @@ xml_in(PG_FUNCTION_ARGS) /* * Parse the data to check if it is well-formed XML data. Assume - * that ERROR occurred if parsing failed. Do we need DTD - * validation (if DTD exists)? + * that ERROR occurred if parsing failed. */ xml_parse(vardata, false, true); @@ -112,6 +112,48 @@ xml_out(PG_FUNCTION_ARGS) } +Datum +xml_recv(PG_FUNCTION_ARGS) +{ +#ifdef USE_LIBXML + StringInfo buf = (StringInfo) PG_GETARG_POINTER(0); + xmltype *result; + char *str; + int nbytes; + + str = pq_getmsgtext(buf, buf->len - buf->cursor, &nbytes); + + result = (xmltype *) palloc(nbytes + VARHDRSZ); + VARATT_SIZEP(result) = nbytes + VARHDRSZ; + memcpy(VARDATA(result), str, nbytes); + pfree(str); + + /* + * Parse the data to check if it is well-formed XML data. Assume + * that ERROR occurred if parsing failed. + */ + xml_parse(result, false, true); + + PG_RETURN_XML_P(result); +#else + NO_XML_SUPPORT(); + return 0; +#endif +} + + +Datum +xml_send(PG_FUNCTION_ARGS) +{ + xmltype *x = PG_GETARG_XML_P(0); + StringInfoData buf; + + pq_begintypsend(&buf); + pq_sendbytes(&buf, VARDATA(x), VARSIZE(x) - VARHDRSZ); + PG_RETURN_BYTEA_P(pq_endtypsend(&buf)); +} + + #ifdef USE_LIBXML static void appendStringInfoText(StringInfo str, const text *t) |