Skip to content

Commit ad1425a

Browse files
committed
Add send and recv functions for xml type.
1 parent d9e1c97 commit ad1425a

File tree

5 files changed

+58
-9
lines changed

5 files changed

+58
-9
lines changed

src/backend/utils/adt/xml.c

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.6 2006/12/28 03:17:38 petere Exp $
10+
* $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.7 2006/12/28 14:28:36 petere Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -34,6 +34,7 @@
3434
#endif /* USE_LIBXML */
3535

3636
#include "fmgr.h"
37+
#include "libpq/pqformat.h"
3738
#include "mb/pg_wchar.h"
3839
#include "nodes/execnodes.h"
3940
#include "utils/builtins.h"
@@ -83,8 +84,7 @@ xml_in(PG_FUNCTION_ARGS)
8384

8485
/*
8586
* Parse the data to check if it is well-formed XML data. Assume
86-
* that ERROR occurred if parsing failed. Do we need DTD
87-
* validation (if DTD exists)?
87+
* that ERROR occurred if parsing failed.
8888
*/
8989
xml_parse(vardata, false, true);
9090

@@ -112,6 +112,48 @@ xml_out(PG_FUNCTION_ARGS)
112112
}
113113

114114

115+
Datum
116+
xml_recv(PG_FUNCTION_ARGS)
117+
{
118+
#ifdef USE_LIBXML
119+
StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
120+
xmltype *result;
121+
char *str;
122+
int nbytes;
123+
124+
str = pq_getmsgtext(buf, buf->len - buf->cursor, &nbytes);
125+
126+
result = (xmltype *) palloc(nbytes + VARHDRSZ);
127+
VARATT_SIZEP(result) = nbytes + VARHDRSZ;
128+
memcpy(VARDATA(result), str, nbytes);
129+
pfree(str);
130+
131+
/*
132+
* Parse the data to check if it is well-formed XML data. Assume
133+
* that ERROR occurred if parsing failed.
134+
*/
135+
xml_parse(result, false, true);
136+
137+
PG_RETURN_XML_P(result);
138+
#else
139+
NO_XML_SUPPORT();
140+
return 0;
141+
#endif
142+
}
143+
144+
145+
Datum
146+
xml_send(PG_FUNCTION_ARGS)
147+
{
148+
xmltype *x = PG_GETARG_XML_P(0);
149+
StringInfoData buf;
150+
151+
pq_begintypsend(&buf);
152+
pq_sendbytes(&buf, VARDATA(x), VARSIZE(x) - VARHDRSZ);
153+
PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
154+
}
155+
156+
115157
#ifdef USE_LIBXML
116158
static void
117159
appendStringInfoText(StringInfo str, const text *t)

src/include/catalog/catversion.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
3838
* Portions Copyright (c) 1994, Regents of the University of California
3939
*
40-
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.366 2006/12/24 00:29:19 tgl Exp $
40+
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.367 2006/12/28 14:28:36 petere Exp $
4141
*
4242
*-------------------------------------------------------------------------
4343
*/
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/* yyyymmddN */
56-
#define CATALOG_VERSION_NO 200612231
56+
#define CATALOG_VERSION_NO 200612281
5757

5858
#endif

src/include/catalog/pg_proc.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.432 2006/12/24 00:29:19 tgl Exp $
10+
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.433 2006/12/28 14:28:36 petere Exp $
1111
*
1212
* NOTES
1313
* 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
39873987
DESCR("perform a non-validating parse of a character string to produce an XML value");
39883988
DATA(insert OID = 2897 ( xmlvalidate PGNSP PGUID 12 f f t f i 2 16 "142 25" _null_ _null_ _null_ xmlvalidate - _null_ ));
39893989
DESCR("validate an XML value");
3990+
DATA(insert OID = 2898 ( xml_recv PGNSP PGUID 12 f f t f s 1 142 "2281" _null_ _null_ _null_ xml_recv - _null_ ));
3991+
DESCR("I/O");
3992+
DATA(insert OID = 2899 ( xml_send PGNSP PGUID 12 f f t f s 1 17 "142" _null_ _null_ _null_ xml_send - _null_ ));
3993+
DESCR("I/O");
3994+
39903995

39913996
/*
39923997
* Symbolic values for provolatile column: these indicate whether the result

src/include/catalog/pg_type.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
99
* Portions Copyright (c) 1994, Regents of the University of California
1010
*
11-
* $PostgreSQL: pgsql/src/include/catalog/pg_type.h,v 1.174 2006/12/28 01:09:01 tgl Exp $
11+
* $PostgreSQL: pgsql/src/include/catalog/pg_type.h,v 1.175 2006/12/28 14:28:36 petere Exp $
1212
*
1313
* NOTES
1414
* 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
316316
#define PG_CLASS_RELTYPE_OID 83
317317

318318
/* OIDS 100 - 199 */
319-
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_ ));
319+
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_ ));
320320
DESCR("XML content");
321321
#define XMLOID 142
322322
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_ ));

src/include/utils/xml.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/utils/xml.h,v 1.3 2006/12/24 00:29:20 tgl Exp $
10+
* $PostgreSQL: pgsql/src/include/utils/xml.h,v 1.4 2006/12/28 14:28:36 petere Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -26,6 +26,8 @@ typedef struct varlena xmltype;
2626

2727
extern Datum xml_in(PG_FUNCTION_ARGS);
2828
extern Datum xml_out(PG_FUNCTION_ARGS);
29+
extern Datum xml_recv(PG_FUNCTION_ARGS);
30+
extern Datum xml_send(PG_FUNCTION_ARGS);
2931
extern Datum xmlcomment(PG_FUNCTION_ARGS);
3032
extern Datum texttoxml(PG_FUNCTION_ARGS);
3133
extern Datum xmlvalidate(PG_FUNCTION_ARGS);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy