From 4b48ad4fb2edf897b87d04467f8eaaaba82a258f Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Fri, 19 Jan 2007 16:58:46 +0000 Subject: Add support for converting binary values (i.e. bytea) into xml values, with new GUC parameter "xmlbinary" that controls the output encoding, as per SQL/XML standard. --- src/backend/utils/adt/xml.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'src/backend/utils/adt/xml.c') diff --git a/src/backend/utils/adt/xml.c b/src/backend/utils/adt/xml.c index 03bbda97ddf..5f3fafe1e70 100644 --- a/src/backend/utils/adt/xml.c +++ b/src/backend/utils/adt/xml.c @@ -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.18 2007/01/18 13:59:11 petere Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.19 2007/01/19 16:58:46 petere Exp $ * *------------------------------------------------------------------------- */ @@ -73,6 +73,8 @@ static xmlDocPtr xml_parse(text *data, bool is_document, bool preserve_whitespac #endif /* USE_LIBXML */ +XmlBinaryType xmlbinary; + #define NO_XML_SUPPORT() \ ereport(ERROR, \ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), \ @@ -1500,6 +1502,28 @@ map_sql_value_to_xml_value(Datum value, Oid type) if (type == XMLOID) return str; +#ifdef USE_LIBXML + if (type == BYTEAOID) + { + xmlBufferPtr buf; + xmlTextWriterPtr writer; + char *result; + + buf = xmlBufferCreate(); + writer = xmlNewTextWriterMemory(buf, 0); + + if (xmlbinary == XMLBINARY_BASE64) + xmlTextWriterWriteBase64(writer, VARDATA(value), 0, VARSIZE(value) - VARHDRSZ); + else + xmlTextWriterWriteBinHex(writer, VARDATA(value), 0, VARSIZE(value) - VARHDRSZ); + + xmlFreeTextWriter(writer); + result = pstrdup((const char *) xmlBufferContent(buf)); + xmlBufferFree(buf); + return result; + } +#endif /* USE_LIBXML */ + for (p = str; *p; p += pg_mblen(p)) { switch (*p) -- cgit v1.2.3