mirror of
https://github.com/postgres/postgres.git
synced 2025-06-16 06:01:02 +03:00
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.
This commit is contained in:
@ -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)
|
||||
|
Reference in New Issue
Block a user