From: Peter Eisentraut Date: Thu, 28 Dec 2006 14:28:36 +0000 (+0000) Subject: Add send and recv functions for xml type. X-Git-Tag: REL8_3_BETA1~1639 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ad1425ae4346f599fc2420c00800a3748fed1259;p=postgresql Add send and recv functions for xml type. --- diff --git a/src/backend/utils/adt/xml.c b/src/backend/utils/adt/xml.c index 83704f6c79..6cde8d6aa4 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) diff --git a/src/include/catalog/catversion.h b/src/include/catalog/catversion.h index 68f5a63934..1b1e07bd71 100644 --- a/src/include/catalog/catversion.h +++ b/src/include/catalog/catversion.h @@ -37,7 +37,7 @@ * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.366 2006/12/24 00:29:19 tgl Exp $ + * $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.367 2006/12/28 14:28:36 petere Exp $ * *------------------------------------------------------------------------- */ @@ -53,6 +53,6 @@ */ /* yyyymmddN */ -#define CATALOG_VERSION_NO 200612231 +#define CATALOG_VERSION_NO 200612281 #endif diff --git a/src/include/catalog/pg_proc.h b/src/include/catalog/pg_proc.h index 0a3ccc07f6..b591300709 100644 --- a/src/include/catalog/pg_proc.h +++ b/src/include/catalog/pg_proc.h @@ -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/include/catalog/pg_proc.h,v 1.432 2006/12/24 00:29:19 tgl Exp $ + * $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.433 2006/12/28 14:28:36 petere Exp $ * * NOTES * The script catalog/genbki.sh reads this file and generates .bki @@ -3987,6 +3987,11 @@ DATA(insert OID = 2896 ( xml PGNSP PGUID 12 f f t f i 1 142 "25" _null_ _n DESCR("perform a non-validating parse of a character string to produce an XML value"); DATA(insert OID = 2897 ( xmlvalidate PGNSP PGUID 12 f f t f i 2 16 "142 25" _null_ _null_ _null_ xmlvalidate - _null_ )); DESCR("validate an XML value"); +DATA(insert OID = 2898 ( xml_recv PGNSP PGUID 12 f f t f s 1 142 "2281" _null_ _null_ _null_ xml_recv - _null_ )); +DESCR("I/O"); +DATA(insert OID = 2899 ( xml_send PGNSP PGUID 12 f f t f s 1 17 "142" _null_ _null_ _null_ xml_send - _null_ )); +DESCR("I/O"); + /* * Symbolic values for provolatile column: these indicate whether the result diff --git a/src/include/catalog/pg_type.h b/src/include/catalog/pg_type.h index b704637d43..9a95ef305b 100644 --- a/src/include/catalog/pg_type.h +++ b/src/include/catalog/pg_type.h @@ -8,7 +8,7 @@ * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/catalog/pg_type.h,v 1.174 2006/12/28 01:09:01 tgl Exp $ + * $PostgreSQL: pgsql/src/include/catalog/pg_type.h,v 1.175 2006/12/28 14:28:36 petere Exp $ * * NOTES * the genbki.sh script reads this file and generates .bki @@ -316,7 +316,7 @@ DATA(insert OID = 83 ( pg_class PGNSP PGUID -1 f c t \054 1259 0 record_in reco #define PG_CLASS_RELTYPE_OID 83 /* OIDS 100 - 199 */ -DATA(insert OID = 142 ( xml PGNSP PGUID -1 f b t \054 0 0 xml_in xml_out - - - i x f 0 -1 0 _null_ _null_ )); +DATA(insert OID = 142 ( xml PGNSP PGUID -1 f b t \054 0 0 xml_in xml_out xml_recv xml_send - i x f 0 -1 0 _null_ _null_ )); DESCR("XML content"); #define XMLOID 142 DATA(insert OID = 143 ( _xml PGNSP PGUID -1 f b t \054 0 142 array_in array_out array_recv array_send - i x f 0 -1 0 _null_ _null_ )); diff --git a/src/include/utils/xml.h b/src/include/utils/xml.h index 713bdaeb11..ca50142032 100644 --- a/src/include/utils/xml.h +++ b/src/include/utils/xml.h @@ -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/include/utils/xml.h,v 1.3 2006/12/24 00:29:20 tgl Exp $ + * $PostgreSQL: pgsql/src/include/utils/xml.h,v 1.4 2006/12/28 14:28:36 petere Exp $ * *------------------------------------------------------------------------- */ @@ -26,6 +26,8 @@ typedef struct varlena xmltype; extern Datum xml_in(PG_FUNCTION_ARGS); extern Datum xml_out(PG_FUNCTION_ARGS); +extern Datum xml_recv(PG_FUNCTION_ARGS); +extern Datum xml_send(PG_FUNCTION_ARGS); extern Datum xmlcomment(PG_FUNCTION_ARGS); extern Datum texttoxml(PG_FUNCTION_ARGS); extern Datum xmlvalidate(PG_FUNCTION_ARGS);