49#include <libxml/chvalid.h>
50#include <libxml/entities.h>
51#include <libxml/parser.h>
52#include <libxml/parserInternals.h>
53#include <libxml/tree.h>
54#include <libxml/uri.h>
55#include <libxml/xmlerror.h>
56#include <libxml/xmlsave.h>
57#include <libxml/xmlversion.h>
58#include <libxml/xmlwriter.h>
59#include <libxml/xpath.h>
60#include <libxml/xpathInternals.h>
67#if LIBXML_VERSION >= 20704
68#define HAVE_XMLSTRUCTUREDERRORCONTEXT 1
74#if LIBXML_VERSION >= 21200
75#define PgXmlErrorPtr const xmlError *
77#define PgXmlErrorPtr xmlErrorPtr
114#define ERRCXT_MAGIC 68275028
134 int sqlcode,
const char *msg);
140#ifdef USE_LIBXMLCONTEXT
175 const char *
targetns,
bool top_level);
189 const char *
targetns,
bool top_level);
194#define XMLTABLE_CONTEXT_MAGIC 46922182
216 const char *path,
int colnum);
219 Oid typid,
int32 typmod,
bool *isnull);
234#define NO_XML_SUPPORT() \
236 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), \
237 errmsg("unsupported XML feature"), \
238 errdetail("This functionality requires the server to be built with libxml support.")))
242#define NAMESPACE_XSD "http://www.w3.org/2001/XMLSchema"
243#define NAMESPACE_XSI "http://www.w3.org/2001/XMLSchema-instance"
244#define NAMESPACE_SQLXML "http://standards.iso.org/iso/9075/2003/sqlxml"
257 errmsg(
"invalid encoding name \"%s\"",
300#define PG_XML_DEFAULT_VERSION "1.0"
387 nbytes =
buf->len -
buf->cursor;
505 errmsg(
"invalid XML comment")));
510 errmsg(
"invalid XML comment")));
543 "could not allocate xmlChar");
680 text *
volatile result;
710 (
Node *) &escontext);
718 errmsg(
"not an XML document")));
745 "could not allocate xmlBuffer");
765 "could not allocate xmlSaveCtxt");
772 "could not save document to xmlBuffer");
789 "could not allocate xml node");
802 "could not append xml node list");
814 "could not allocate xml node");
825 "could not save newline to xmlBuffer");
833 "could not save content to xmlBuffer");
844 "could not close xmlSaveCtxtPtr");
855 while (
len > 0 && (
str[
len - 1] ==
'\n' ||
894 const Datum *named_argvalue,
const bool *named_argnull,
895 const Datum *argvalue,
const bool *argnull)
922 if (named_argnull[
i])
957 "could not allocate xmlBuffer");
961 "could not allocate xmlTextWriter");
966 "could not start xml element");
980 "could not write xml attribute");
991 "could not write raw xml text");
997 "could not end xml element");
1058 errmsg(
"invalid XML processing instruction"),
1059 errdetail(
"XML processing instruction target name cannot be \"%s\".", target)));
1081 errmsg(
"invalid XML processing instruction"),
1082 errdetail(
"XML processing instruction cannot contain \"?>\".")));
1161 errmsg(
"xmlvalidate is not implemented")));
1215 if (
sizeof(
char) !=
sizeof(
xmlChar))
1217 (
errmsg(
"could not initialize XML library"),
1218 errdetail(
"libxml2 has incompatible char type: sizeof(char)=%zu, sizeof(xmlChar)=%zu.",
1219 sizeof(
char),
sizeof(
xmlChar))));
1221#ifdef USE_LIBXMLCONTEXT
1261 errcxt->err_occurred =
false;
1273#ifdef HAVE_XMLSTRUCTUREDERRORCONTEXT
1295#ifdef HAVE_XMLSTRUCTUREDERRORCONTEXT
1304 errmsg(
"could not set up XML error handler"),
1305 errhint(
"This probably indicates that the version of libxml2"
1306 " being used is not compatible with the libxml2"
1307 " header files that PostgreSQL was built with.")));
1349#ifdef HAVE_XMLSTRUCTUREDERRORCONTEXT
1356 elog(
WARNING,
"libxml error handling state is out of sync with xml.c");
1380 return errcxt->err_occurred;
1393#define CHECK_XML_SPACE(p) \
1395 if (!xmlIsBlank_ch(*(p))) \
1396 return XML_ERR_SPACE_REQUIRED; \
1399#define SKIP_XML_SPACE(p) \
1400 while (xmlIsBlank_ch(*(p))) (p)++
1404#define PG_XMLISNAMECHAR(c) \
1405 (xmlIsBaseChar_ch(c) || xmlIsIdeographicQ(c) \
1406 || xmlIsDigit_ch(c) \
1407 || c == '.' || c == '-' || c == '_' || c == ':' \
1408 || xmlIsCombiningQ(c) \
1409 || xmlIsExtender_ch(c))
1528 if (*p ==
'\'' || *p ==
'"')
1556 if (*p ==
'\'' || *p ==
'"')
1736 if (!p || p[2] !=
'>')
1870 "could not allocate parser context");
1895 "invalid XML document");
1899 "invalid XML content");
1909 "could not allocate XML document");
1915 "could not allocate XML document");
1931 "invalid XML content");
1977#ifdef USE_LIBXMLCONTEXT
2066 elog(
ERROR,
"xml_ereport called with invalid PgXmlErrorContext");
2069 errcxt->err_occurred =
false;
2072 if (
errcxt->err_buf.len > 0)
2073 detail =
errcxt->err_buf.data;
2098 int sqlcode,
const char *msg)
2104 elog(
ERROR,
"xml_errsave called with invalid PgXmlErrorContext");
2107 errcxt->err_occurred =
false;
2110 if (
errcxt->err_buf.len > 0)
2111 detail =
errcxt->err_buf.data;
2134 int domain =
error->domain;
2135 int level =
error->level;
2145 elog(
FATAL,
"xml_errorHandler called with invalid PgXmlErrorContext");
2155 switch (
error->code)
2215 if (
error->line > 0)
2353 while (
str->len > 0 &&
str->data[
str->len - 1] ==
'\n')
2354 str->data[--
str->len] =
'\0';
2397 ||
c ==
'_' ||
c ==
':');
2407 ||
c ==
'.' ||
c ==
'-' ||
c ==
'_' ||
c ==
':'
2437 else if (*p ==
'_' && *(p + 1) ==
'x')
2483 if (*p ==
'_' && *(p + 1) ==
'x'
2484 &&
isxdigit((
unsigned char) *(p + 2))
2485 &&
isxdigit((
unsigned char) *(p + 3))
2486 &&
isxdigit((
unsigned char) *(p + 4))
2487 &&
isxdigit((
unsigned char) *(p + 5))
2537 &elem_values, &elem_nulls,
2542 for (
i = 0;
i < num_elems;
i++)
2592 errmsg(
"date out of range"),
2593 errdetail(
"XML does not support infinite date values.")));
2614 errmsg(
"timestamp out of range"),
2615 errdetail(
"XML does not support infinite timestamp values.")));
2621 errmsg(
"timestamp out of range")));
2632 const char *tzn =
NULL;
2641 errmsg(
"timestamp out of range"),
2642 errdetail(
"XML does not support infinite timestamp values.")));
2648 errmsg(
"timestamp out of range")));
2669 "could not allocate xmlBuffer");
2673 "could not allocate xmlTextWriter");
2741 for (p =
str; *p; p++)
2832 elog(
ERROR,
"SPI_execute returned %s for %s",
2859 " WHERE relnamespace = %u AND relkind IN ("
2863 " AND pg_catalog.has_table_privilege (oid, 'SELECT')"
2864 " ORDER BY relname;",
nspid);
2874#define XML_VISIBLE_SCHEMAS_EXCLUDE "(nspname ~ '^pg_' OR nspname = 'information_schema')"
2876#define XML_VISIBLE_SCHEMAS "SELECT oid FROM pg_catalog.pg_namespace WHERE pg_catalog.has_schema_privilege (oid, 'USAGE') AND NOT " XML_VISIBLE_SCHEMAS_EXCLUDE
2891 " WHERE relkind IN ("
2895 " AND pg_catalog.has_table_privilege(pg_class.oid, 'SELECT')"
2908 const char *
targetns,
bool top_level)
2976 errmsg(
"cursor \"%s\" does not exist",
name)));
3041 const char *
targetns,
bool top_level)
3058 errmsg(
"invalid query")));
3116 elog(
ERROR,
"SPI_prepare(\"%s\") failed", query);
3119 elog(
ERROR,
"SPI_cursor_open(\"%s\") failed", query);
3146 errmsg(
"cursor \"%s\" does not exist",
name)));
3150 errmsg(
"portal \"%s\" does not return tuples",
name)));
3197 elog(
ERROR,
"SPI_prepare(\"%s\") failed", query);
3200 elog(
ERROR,
"SPI_cursor_open(\"%s\") failed", query);
3292 " targetNamespace=\"%s\"\n"
3293 " elementFormDefault=\"qualified\"",
3572 elog(
ERROR,
"cache lookup failed for relation %u", relid);
3607 "<xsd:complexType name=\"%s\">\n"
3608 " <xsd:sequence>\n",
3611 for (
i = 0;
i < tupdesc->
natts;
i++)
3615 if (
att->attisdropped)
3618 " <xsd:element name=\"%s\" type=\"%s\"%s></xsd:element>\n",
3622 nulls ?
" nillable=\"true\"" :
" minOccurs=\"0\"");
3626 " </xsd:sequence>\n"
3627 "</xsd:complexType>\n\n");
3632 "<xsd:complexType name=\"%s\">\n"
3634 " <xsd:element name=\"row\" type=\"%s\" minOccurs=\"0\" maxOccurs=\"unbounded\"/>\n"
3635 " </xsd:sequence>\n"
3636 "</xsd:complexType>\n\n",
3640 "<xsd:element name=\"%s\" type=\"%s\"/>\n\n",
3645 "<xsd:element name=\"%s\" type=\"%s\"/>\n\n",
3688 " <xsd:sequence>\n");
3702 " <xsd:element name=\"%s\" type=\"%s\"/>\n",
3706 " <xsd:element name=\"%s\" type=\"%s\" minOccurs=\"0\" maxOccurs=\"unbounded\"/>\n",
3715 " </xsd:sequence>\n");
3717 "</xsd:complexType>\n\n");
3720 "<xsd:element name=\"%s\" type=\"%s\"/>\n\n",
3768 " <xsd:element name=\"%s\" type=\"%s\"/>\n",
3775 "</xsd:complexType>\n\n");
3778 "<xsd:element name=\"%s\" type=\"%s\"/>\n\n",
3814 ((typmod -
VARHDRSZ) >> 16) & 0xffff,
3906 for (
i = 0;
i < tupdesc->
natts;
i++)
3910 if (
att->attisdropped)
3959 "<xsd:complexType mixed=\"true\">\n"
3961 " <xsd:any name=\"element\" minOccurs=\"0\" maxOccurs=\"unbounded\" processContents=\"skip\"/>\n"
3962 " </xsd:sequence>\n"
3963 "</xsd:complexType>\n");
3968 "<xsd:simpleType name=\"%s\">\n",
typename);
3976 " <xsd:restriction base=\"xsd:string\">\n");
3979 " <xsd:maxLength value=\"%d\"/>\n",
3986 " <xsd:restriction base=\"xsd:%s\">\n"
3987 " </xsd:restriction>\n",
3994 " <xsd:restriction base=\"xsd:decimal\">\n"
3995 " <xsd:totalDigits value=\"%d\"/>\n"
3996 " <xsd:fractionDigits value=\"%d\"/>\n"
3997 " </xsd:restriction>\n",
3998 ((typmod -
VARHDRSZ) >> 16) & 0xffff,
4004 " <xsd:restriction base=\"xsd:short\">\n"
4005 " <xsd:maxInclusive value=\"%d\"/>\n"
4006 " <xsd:minInclusive value=\"%d\"/>\n"
4007 " </xsd:restriction>\n",
4013 " <xsd:restriction base=\"xsd:int\">\n"
4014 " <xsd:maxInclusive value=\"%d\"/>\n"
4015 " <xsd:minInclusive value=\"%d\"/>\n"
4016 " </xsd:restriction>\n",
4022 " <xsd:restriction base=\"xsd:long\">\n"
4025 " </xsd:restriction>\n",
4032 " <xsd:restriction base=\"xsd:float\"></xsd:restriction>\n");
4037 " <xsd:restriction base=\"xsd:double\"></xsd:restriction>\n");
4042 " <xsd:restriction base=\"xsd:boolean\"></xsd:restriction>\n");
4048 const char *tz = (
typeoid ==
TIMETZOID ?
"(\\+|-)\\p{Nd}{2}:\\p{Nd}{2}" :
"");
4052 " <xsd:restriction base=\"xsd:time\">\n"
4053 " <xsd:pattern value=\"\\p{Nd}{2}:\\p{Nd}{2}:\\p{Nd}{2}(.\\p{Nd}+)?%s\"/>\n"
4054 " </xsd:restriction>\n", tz);
4055 else if (typmod == 0)
4057 " <xsd:restriction base=\"xsd:time\">\n"
4058 " <xsd:pattern value=\"\\p{Nd}{2}:\\p{Nd}{2}:\\p{Nd}{2}%s\"/>\n"
4059 " </xsd:restriction>\n", tz);
4062 " <xsd:restriction base=\"xsd:time\">\n"
4063 " <xsd:pattern value=\"\\p{Nd}{2}:\\p{Nd}{2}:\\p{Nd}{2}.\\p{Nd}{%d}%s\"/>\n"
4064 " </xsd:restriction>\n", typmod -
VARHDRSZ, tz);
4075 " <xsd:restriction base=\"xsd:dateTime\">\n"
4076 " <xsd:pattern value=\"\\p{Nd}{4}-\\p{Nd}{2}-\\p{Nd}{2}T\\p{Nd}{2}:\\p{Nd}{2}:\\p{Nd}{2}(.\\p{Nd}+)?%s\"/>\n"
4077 " </xsd:restriction>\n", tz);
4078 else if (typmod == 0)
4080 " <xsd:restriction base=\"xsd:dateTime\">\n"
4081 " <xsd:pattern value=\"\\p{Nd}{4}-\\p{Nd}{2}-\\p{Nd}{2}T\\p{Nd}{2}:\\p{Nd}{2}:\\p{Nd}{2}%s\"/>\n"
4082 " </xsd:restriction>\n", tz);
4085 " <xsd:restriction base=\"xsd:dateTime\">\n"
4086 " <xsd:pattern value=\"\\p{Nd}{4}-\\p{Nd}{2}-\\p{Nd}{2}T\\p{Nd}{2}:\\p{Nd}{2}:\\p{Nd}{2}.\\p{Nd}{%d}%s\"/>\n"
4087 " </xsd:restriction>\n", typmod -
VARHDRSZ, tz);
4093 " <xsd:restriction base=\"xsd:date\">\n"
4094 " <xsd:pattern value=\"\\p{Nd}{4}-\\p{Nd}{2}-\\p{Nd}{2}\"/>\n"
4095 " </xsd:restriction>\n");
4102 int32 base_typmod = -1;
4107 " <xsd:restriction base=\"%s\"/>\n",
4126 const char *
targetns,
bool top_level)
4211 "could not allocate xmlBuffer");
4228 "could not copy node");
4233 if (bytes == -1 ||
xmlerrcxt->err_occurred)
4235 "could not dump node");
4259 "could not allocate xmlChar");
4305 result =
xpathobj->nodesetval->nodeNr;
4310 for (
i = 0;
i < result;
i++)
4343 elog(
ERROR,
"xpath expression result type %d is unsupported",
4399 ndim = namespaces ?
ARR_NDIM(namespaces) : 0;
4406 if (ndim != 2 || dims[1] != 2)
4409 errmsg(
"invalid array for XML namespace mapping"),
4410 errdetail(
"The array must be two-dimensional with length of the second axis equal to 2.")));
4434 errmsg(
"empty XPath expression")));
4462 "could not allocate parser context");
4467 "could not parse XML document");
4471 "could not allocate XPath context");
4486 errmsg(
"neither namespace name nor URI may be null")));
4493 (
errmsg(
"could not register XML namespace with name \"%s\" and URI \"%s\"",
4507 "invalid XPath expression");
4519 "could not create XPath object");
4708 elog(
ERROR,
"%s called with invalid TableFuncScanState", fname);
4711 elog(
ERROR,
"%s called with invalid TableFuncScanState", fname);
4738 xtCxt->natts = natts;
4750 "could not allocate parser context");
4804 "could not parse XML document");
4808 "could not allocate XPath context");
4842 errmsg(
"DEFAULT namespace is not supported")));
4849 "could not set XML namespace");
4871 errmsg(
"row path filter must not be empty string")));
4881 "invalid XPath expression");
4905 errmsg(
"column path filter must not be empty string")));
4913 if (
xtCxt->xpathscomp[colnum] ==
NULL ||
xtCxt->xmlerrcxt->err_occurred)
4915 "invalid XPath expression");
4942 "could not create XPath object");
4944 xtCxt->row_count = 0;
4949 if (
xtCxt->xpathobj->nodesetval !=
NULL)
4951 if (
xtCxt->row_count++ <
xtCxt->xpathobj->nodesetval->nodeNr)
4973 Oid typid,
int32 typmod,
bool *isnull)
4999 cur =
xtCxt->xpathobj->nodesetval->nodeTab[
xtCxt->row_count - 1];
5006 "could not create XPath object");
5020 count =
xpathobj->nodesetval->nodeNr;
5035 for (
int i = 0;
i < count;
i++)
5052 errmsg(
"more than one value returned by column XPath expression")));
5102 state->typioparams[colnum],
#define PG_GETARG_ARRAYTYPE_P(n)
#define DatumGetArrayTypeP(X)
ArrayBuildState * accumArrayResult(ArrayBuildState *astate, Datum dvalue, bool disnull, Oid element_type, MemoryContext rcontext)
ArrayBuildState * initArrayResult(Oid element_type, MemoryContext rcontext, bool subcontext)
void deconstruct_array_builtin(const ArrayType *array, Oid elmtype, Datum **elemsp, bool **nullsp, int *nelemsp)
Datum makeArrayResult(ArrayBuildState *astate, MemoryContext rcontext)
void deconstruct_array(const ArrayType *array, Oid elmtype, int elmlen, bool elmbyval, char elmalign, Datum **elemsp, bool **nullsp, int *nelemsp)
void j2date(int jd, int *year, int *month, int *day)
void EncodeDateTime(struct pg_tm *tm, fsec_t fsec, bool print_tz, int tz, const char *tzn, int style, char *str)
void EncodeDateOnly(struct pg_tm *tm, int style, char *str)
int timestamp2tm(Timestamp dt, int *tzp, struct pg_tm *tm, fsec_t *fsec, const char **tzn, pg_tz *attimezone)
#define TextDatumGetCString(d)
#define Assert(condition)
#define OidIsValid(objectId)
#define TIMESTAMP_NOT_FINITE(j)
#define POSTGRES_EPOCH_JDATE
#define DATE_NOT_FINITE(j)
static DateADT DatumGetDateADT(Datum X)
int errmsg_internal(const char *fmt,...)
int errdetail_internal(const char *fmt,...)
int errdetail(const char *fmt,...)
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define errsave(context,...)
#define ereport(elevel,...)
#define palloc_object(type)
#define palloc0_array(type, count)
#define palloc0_object(type)
Datum InputFunctionCall(FmgrInfo *flinfo, char *str, Oid typioparam, int32 typmod)
char * OidOutputFunctionCall(Oid functionId, Datum val)
#define PG_GETARG_TEXT_PP(n)
#define PG_RETURN_BYTEA_P(x)
#define DatumGetByteaPP(X)
#define PG_GETARG_POINTER(n)
#define PG_RETURN_CSTRING(x)
#define DirectFunctionCall1(func, arg1)
#define PG_GETARG_CSTRING(n)
#define PG_GETARG_NAME(n)
#define PG_RETURN_TEXT_P(x)
#define PG_GETARG_INT32(n)
#define PG_GETARG_BOOL(n)
#define PG_RETURN_DATUM(x)
#define PG_RETURN_BOOL(x)
#define HeapTupleIsValid(tuple)
static void * GETSTRUCT(const HeapTupleData *tuple)
List * lappend(List *list, void *datum)
List * lappend_oid(List *list, Oid datum)
List * list_append_unique_oid(List *list, Oid datum)
char * get_rel_name(Oid relid)
char * get_database_name(Oid dbid)
void getTypeOutputInfo(Oid type, Oid *typOutput, bool *typIsVarlena)
void get_typlenbyvalalign(Oid typid, int16 *typlen, bool *typbyval, char *typalign)
char get_typtype(Oid typid)
Oid getBaseTypeAndTypmod(Oid typid, int32 *typmod)
Oid getBaseType(Oid typid)
char * get_namespace_name(Oid nspid)
void get_type_category_preferred(Oid typid, char *typcategory, bool *typispreferred)
#define type_is_array_domain(typid)
int GetDatabaseEncoding(void)
char * pg_any_to_server(const char *s, int len, int encoding)
unsigned char * pg_do_encoding_conversion(unsigned char *src, int len, int src_encoding, int dest_encoding)
int pg_get_client_encoding(void)
void pg_unicode_to_server(char32_t c, unsigned char *s)
char * pg_server_to_any(const char *s, int len, int encoding)
int pg_encoding_mb2wchar_with_len(int encoding, const char *from, pg_wchar *to, int len)
int pg_mblen(const char *mbstr)
char * MemoryContextStrdup(MemoryContext context, const char *string)
void * MemoryContextAlloc(MemoryContext context, Size size)
char * pstrdup(const char *in)
void * repalloc(void *pointer, Size size)
void pfree(void *pointer)
MemoryContext TopMemoryContext
MemoryContext CurrentMemoryContext
#define AllocSetContextCreate
#define ALLOCSET_DEFAULT_SIZES
Oid LookupExplicitNamespace(const char *nspname, bool missing_ok)
Oid exprType(const Node *expr)
#define IsA(nodeptr, _type_)
FormData_pg_attribute * Form_pg_attribute
#define ERRCODE_DATA_CORRUPTED
FormData_pg_class * Form_pg_class
#define forboth(cell1, list1, cell2, list2)
#define list_make2(x1, x2)
static char buf[DEFAULT_XLOG_SEG_SIZE]
FormData_pg_type * Form_pg_type
#define MAX_MULTIBYTE_CHAR_LEN
#define MAX_UNICODE_EQUIVALENT_STRING
#define pg_encoding_to_char
#define pg_char_to_encoding
int pg_strcasecmp(const char *s1, const char *s2)
int pg_strncasecmp(const char *s1, const char *s2, size_t n)
static bool DatumGetBool(Datum X)
static Datum PointerGetDatum(const void *X)
static Oid DatumGetObjectId(Datum X)
static Datum BoolGetDatum(bool X)
static Datum ObjectIdGetDatum(Oid X)
static char * DatumGetCString(Datum X)
static Datum Float8GetDatum(float8 X)
static Datum CStringGetDatum(const char *X)
Datum regclassout(PG_FUNCTION_ARGS)
Oid SPI_gettypeid(TupleDesc tupdesc, int fnumber)
const char * SPI_result_code_string(int code)
SPITupleTable * SPI_tuptable
Portal SPI_cursor_find(const char *name)
Portal SPI_cursor_open(const char *name, SPIPlanPtr plan, const Datum *Values, const char *Nulls, bool read_only)
void SPI_cursor_fetch(Portal portal, bool forward, long count)
SPIPlanPtr SPI_prepare(const char *src, int nargs, Oid *argtypes)
void SPI_cursor_close(Portal portal)
void * SPI_palloc(Size size)
int SPI_execute(const char *src, bool read_only, long tcount)
Datum SPI_getbinval(HeapTuple tuple, TupleDesc tupdesc, int fnumber, bool *isnull)
char * SPI_fname(TupleDesc tupdesc, int fnumber)
struct StringInfoData * StringInfo
StringInfo makeStringInfo(void)
void appendStringInfo(StringInfo str, const char *fmt,...)
void appendBinaryStringInfo(StringInfo str, const void *data, int datalen)
void appendStringInfoString(StringInfo str, const char *s)
void appendStringInfoChar(StringInfo str, char ch)
void initStringInfo(StringInfo str)
#define appendStringInfoCharMacro(str, ch)
void(* InitOpaque)(TableFuncScanState *state, int natts)
void ReleaseSysCache(HeapTuple tuple)
HeapTuple SearchSysCache1(int cacheId, Datum key1)
void table_close(Relation relation, LOCKMODE lockmode)
Relation table_open(Oid relationId, LOCKMODE lockmode)
TupleDesc CreateTupleDescCopy(TupleDesc tupdesc)
static FormData_pg_attribute * TupleDescAttr(TupleDesc tupdesc, int i)
struct TupleDescData * TupleDesc
static Timestamp DatumGetTimestamp(Datum X)
static Size VARSIZE_ANY_EXHDR(const void *PTR)
static Size VARSIZE(const void *PTR)
static char * VARDATA(const void *PTR)
static char * VARDATA_ANY(const void *PTR)
static void SET_VARSIZE(void *PTR, Size len)
static void appendStringInfoText(StringInfo str, const text *t)
text * cstring_to_text_with_len(const char *s, int len)
text * cstring_to_text(const char *s)
char * text_to_cstring(const text *t)
int pg_encoding_mblen(int encoding, const char *mbstr)
Datum xml_in(PG_FUNCTION_ARGS)
Datum cursor_to_xmlschema(PG_FUNCTION_ARGS)
Datum table_to_xml(PG_FUNCTION_ARGS)
Datum query_to_xmlschema(PG_FUNCTION_ARGS)
Datum database_to_xml(PG_FUNCTION_ARGS)
static const char * map_sql_catalog_to_xmlschema_types(List *nspid_list, bool nulls, bool tableforest, const char *targetns)
xmltype * xmlroot(xmltype *data, text *version, int standalone)
static void XmlTableInitOpaque(struct TableFuncScanState *state, int natts)
static const char * map_sql_type_to_xml_name(Oid typeoid, int typmod)
static const char * map_sql_type_to_xmlschema_type(Oid typeoid, int typmod)
Datum texttoxml(PG_FUNCTION_ARGS)
static char * xml_out_internal(xmltype *x, pg_enc target_encoding)
char * map_sql_identifier_to_xml_name(const char *ident, bool fully_escaped, bool escape_period)
static void xsd_schema_element_start(StringInfo result, const char *targetns)
Datum query_to_xml_and_xmlschema(PG_FUNCTION_ARGS)
Datum xmltotext(PG_FUNCTION_ARGS)
Datum schema_to_xml_and_xmlschema(PG_FUNCTION_ARGS)
Datum xmlexists(PG_FUNCTION_ARGS)
Datum xmltext(PG_FUNCTION_ARGS)
static char * map_multipart_sql_identifier_to_xml_name(const char *a, const char *b, const char *c, const char *d)
static StringInfo database_to_xmlschema_internal(bool nulls, bool tableforest, const char *targetns)
Datum database_to_xmlschema(PG_FUNCTION_ARGS)
static List * schema_get_xml_visible_tables(Oid nspid)
Datum schema_to_xmlschema(PG_FUNCTION_ARGS)
text * xmltotext_with_options(xmltype *data, XmlOptionType xmloption_arg, bool indent)
static void xmldata_root_element_start(StringInfo result, const char *eltname, const char *xmlschema, const char *targetns, bool top_level)
char * map_sql_value_to_xml_value(Datum value, Oid type, bool xml_escape_strings)
Datum xml_send(PG_FUNCTION_ARGS)
static const char * map_sql_schema_to_xmlschema_types(Oid nspid, List *relid_list, bool nulls, bool tableforest, const char *targetns)
const TableFuncRoutine XmlTableRoutine
Datum xmlcomment(PG_FUNCTION_ARGS)
static void XmlTableSetNamespace(struct TableFuncScanState *state, const char *name, const char *uri)
Datum xmlconcat2(PG_FUNCTION_ARGS)
static void XmlTableSetRowFilter(struct TableFuncScanState *state, const char *path)
static List * database_get_xml_visible_schemas(void)
static void xmldata_root_element_end(StringInfo result, const char *eltname)
xmltype * xmlconcat(List *args)
static Datum XmlTableGetValue(struct TableFuncScanState *state, int colnum, Oid typid, int32 typmod, bool *isnull)
char * escape_xml(const char *str)
Datum xml_is_well_formed_document(PG_FUNCTION_ARGS)
Datum query_to_xml(PG_FUNCTION_ARGS)
static StringInfo database_to_xml_internal(const char *xmlschema, bool nulls, bool tableforest, const char *targetns)
static xmltype * stringinfo_to_xmltype(StringInfo buf)
Datum xml_is_well_formed_content(PG_FUNCTION_ARGS)
#define XML_VISIBLE_SCHEMAS
static List * database_get_xml_visible_tables(void)
bool xml_is_document(xmltype *arg)
static StringInfo schema_to_xmlschema_internal(const char *schemaname, bool nulls, bool tableforest, const char *targetns)
Datum table_to_xml_and_xmlschema(PG_FUNCTION_ARGS)
Datum xmlvalidate(PG_FUNCTION_ARGS)
xmltype * xmlparse(text *data, XmlOptionType xmloption_arg, bool preserve_whitespace)
static xmltype * cstring_to_xmltype(const char *string)
static List * query_to_oid_list(const char *query)
static void XmlTableSetDocument(struct TableFuncScanState *state, Datum value)
static void XmlTableDestroyOpaque(struct TableFuncScanState *state)
static const char * map_sql_typecoll_to_xmlschema_types(List *tupdesc_list)
#define PG_XML_DEFAULT_VERSION
Datum table_to_xmlschema(PG_FUNCTION_ARGS)
static StringInfo query_to_xml_internal(const char *query, char *tablename, const char *xmlschema, bool nulls, bool tableforest, const char *targetns, bool top_level)
static void SPI_sql_row_to_xmlelement(uint64 rownum, StringInfo result, char *tablename, bool nulls, bool tableforest, const char *targetns, bool top_level)
static StringInfo schema_to_xml_internal(Oid nspid, const char *xmlschema, bool nulls, bool tableforest, const char *targetns, bool top_level)
static StringInfo table_to_xml_internal(Oid relid, const char *xmlschema, bool nulls, bool tableforest, const char *targetns, bool top_level)
Datum schema_to_xml(PG_FUNCTION_ARGS)
char * map_xml_name_to_sql_identifier(const char *name)
Datum database_to_xml_and_xmlschema(PG_FUNCTION_ARGS)
static bool XmlTableFetchRow(struct TableFuncScanState *state)
Datum cursor_to_xml(PG_FUNCTION_ARGS)
Datum xpath_exists(PG_FUNCTION_ARGS)
Datum xml_is_well_formed(PG_FUNCTION_ARGS)
static char * _SPI_strdup(const char *s)
static void XmlTableSetColumnFilter(struct TableFuncScanState *state, const char *path, int colnum)
static const char * map_sql_table_to_xmlschema(TupleDesc tupdesc, Oid relid, bool nulls, bool tableforest, const char *targetns)
Datum xml_out(PG_FUNCTION_ARGS)
Datum xml_recv(PG_FUNCTION_ARGS)
xmltype * xmlelement(XmlExpr *xexpr, const Datum *named_argvalue, const bool *named_argnull, const Datum *argvalue, const bool *argnull)
xmltype * xmlpi(const char *target, text *arg, bool arg_is_null, bool *result_is_null)
Datum xpath(PG_FUNCTION_ARGS)
static void xsd_schema_element_end(StringInfo result)
@ XML_STANDALONE_NO_VALUE
struct PgXmlErrorContext PgXmlErrorContext
PgXmlErrorContext * pg_xml_init(PgXmlStrictness strictness)
#define PG_RETURN_XML_P(x)
void xml_ereport(PgXmlErrorContext *errcxt, int level, int sqlcode, const char *msg)
bool pg_xml_error_occurred(PgXmlErrorContext *errcxt)
static xmltype * DatumGetXmlP(Datum X)
void pg_xml_done(PgXmlErrorContext *errcxt, bool isError)
#define PG_GETARG_XML_P(n)
void pg_xml_init_library(void)
@ PG_XML_STRICTNESS_LEGACY
@ PG_XML_STRICTNESS_WELLFORMED