PostgreSQL Source Code: src/backend/utils/adt/xml.c File Reference (original) (raw)
Go to the source code of this file.
Macros | |
---|---|
#define | NO_XML_SUPPORT() |
#define | NAMESPACE_XSD "http://www.w3.org/2001/XMLSchema" |
#define | NAMESPACE_XSI "http://www.w3.org/2001/XMLSchema-instance" |
#define | NAMESPACE_SQLXML "http://standards.iso.org/iso/9075/2003/sqlxml" |
#define | PG_XML_DEFAULT_VERSION "1.0" |
#define | XML_VISIBLE_SCHEMAS_EXCLUDE "(nspname ~ '^pg_' OR nspname = 'information_schema')" |
#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 |
Variables | |
---|---|
int | xmlbinary = XMLBINARY_BASE64 |
int | xmloption = XMLOPTION_CONTENT |
const TableFuncRoutine | XmlTableRoutine |
◆ NAMESPACE_SQLXML
#define NAMESPACE_SQLXML "http://standards.iso.org/iso/9075/2003/sqlxml"
Definition at line 245 of file xml.c.
◆ NAMESPACE_XSD
#define NAMESPACE_XSD "http://www.w3.org/2001/XMLSchema"
Definition at line 243 of file xml.c.
◆ NAMESPACE_XSI
#define NAMESPACE_XSI "http://www.w3.org/2001/XMLSchema-instance"
Definition at line 244 of file xml.c.
◆ NO_XML_SUPPORT
#define NO_XML_SUPPORT | ( | ) |
---|
Value:
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), \
errmsg("unsupported XML feature"), \
errdetail("This functionality requires the server to be built with libxml support.")))
int errdetail(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
Definition at line 235 of file xml.c.
◆ PG_XML_DEFAULT_VERSION
#define PG_XML_DEFAULT_VERSION "1.0"
Definition at line 301 of file xml.c.
◆ XML_VISIBLE_SCHEMAS
#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
Definition at line 2849 of file xml.c.
◆ XML_VISIBLE_SCHEMAS_EXCLUDE
#define XML_VISIBLE_SCHEMAS_EXCLUDE "(nspname ~ '^pg_' OR nspname = 'information_schema')"
Definition at line 2847 of file xml.c.
◆ _SPI_strdup()
static char * _SPI_strdup ( const char * s) | static |
---|
◆ cstring_to_xmltype()
static xmltype * cstring_to_xmltype ( const char * string) | static |
---|
◆ cursor_to_xml()
Definition at line 2924 of file xml.c.
2925{
2931
2935
2937
2938 if (!tableforest)
2939 {
2942 }
2943
2946 if (portal == NULL)
2948 (errcode(ERRCODE_UNDEFINED_CURSOR),
2949 errmsg("cursor \"%s\" does not exist", name)));
2950
2954 tableforest, targetns, true);
2955
2957
2958 if (!tableforest)
2960
2962}
#define PG_GETARG_TEXT_PP(n)
#define PG_GETARG_INT32(n)
#define PG_GETARG_BOOL(n)
Portal SPI_cursor_find(const char *name)
void SPI_cursor_fetch(Portal portal, bool forward, long count)
void appendStringInfoChar(StringInfo str, char ch)
void initStringInfo(StringInfo str)
char * text_to_cstring(const text *t)
static void xmldata_root_element_start(StringInfo result, const char *eltname, const char *xmlschema, const char *targetns, bool top_level)
static void xmldata_root_element_end(StringInfo result, const char *eltname)
static xmltype * stringinfo_to_xmltype(StringInfo buf)
static void SPI_sql_row_to_xmlelement(uint64 rownum, StringInfo result, char *tablename, bool nulls, bool tableforest, const char *targetns, bool top_level)
#define PG_RETURN_XML_P(x)
References appendStringInfoChar(), ereport, errcode(), errmsg(), ERROR, i, initStringInfo(), name, PG_GETARG_BOOL, PG_GETARG_INT32, PG_GETARG_TEXT_PP, PG_RETURN_XML_P, SPI_connect(), SPI_cursor_fetch(), SPI_cursor_find(), SPI_finish(), SPI_processed, SPI_sql_row_to_xmlelement(), stringinfo_to_xmltype(), text_to_cstring(), xmldata_root_element_end(), and xmldata_root_element_start().
◆ cursor_to_xmlschema()
Definition at line 3105 of file xml.c.
3106{
3111 const char *xmlschema;
3113
3116 if (portal == NULL)
3118 (errcode(ERRCODE_UNDEFINED_CURSOR),
3119 errmsg("cursor \"%s\" does not exist", name)));
3120 if (portal->tupDesc == NULL)
3122 (errcode(ERRCODE_INVALID_CURSOR_STATE),
3123 errmsg("portal \"%s\" does not return tuples", name)));
3124
3127 tableforest, targetns));
3129
3131}
static xmltype * cstring_to_xmltype(const char *string)
static char * _SPI_strdup(const char *s)
static const char * map_sql_table_to_xmlschema(TupleDesc tupdesc, Oid relid, bool nulls, bool tableforest, const char *targetns)
References _SPI_strdup(), cstring_to_xmltype(), ereport, errcode(), errmsg(), ERROR, InvalidOid, map_sql_table_to_xmlschema(), name, PG_GETARG_BOOL, PG_GETARG_TEXT_PP, PG_RETURN_XML_P, SPI_connect(), SPI_cursor_find(), SPI_finish(), text_to_cstring(), and PortalData::tupDesc.
◆ database_get_xml_visible_schemas()
static List * database_get_xml_visible_schemas ( void ) | static |
---|
◆ database_get_xml_visible_tables()
static List * database_get_xml_visible_tables ( void ) | static |
---|
◆ database_to_xml()
◆ database_to_xml_and_xmlschema()
Definition at line 3477 of file xml.c.
3478{
3483
3485
3487 nulls, tableforest, targetns)));
3488}
static StringInfo database_to_xmlschema_internal(bool nulls, bool tableforest, const char *targetns)
References StringInfoData::data, database_to_xml_internal(), database_to_xmlschema_internal(), PG_GETARG_BOOL, PG_GETARG_TEXT_PP, PG_RETURN_XML_P, stringinfo_to_xmltype(), and text_to_cstring().
◆ database_to_xml_internal()
static StringInfo database_to_xml_internal ( const char * xmlschema, bool nulls, bool tableforest, const char * targetns ) | static |
---|
Definition at line 3367 of file xml.c.
3369{
3371 List *nspid_list;
3373 char *xmlcn;
3374
3376 true, false);
3378
3381
3382 if (xmlschema)
3384
3386
3388
3389 foreach(cell, nspid_list)
3390 {
3393
3395 tableforest, targetns, false);
3396
3399 }
3400
3402
3404
3405 return result;
3406}
char * get_database_name(Oid dbid)
StringInfo makeStringInfo(void)
void appendStringInfo(StringInfo str, const char *fmt,...)
void appendBinaryStringInfo(StringInfo str, const void *data, int datalen)
char * map_sql_identifier_to_xml_name(const char *ident, bool fully_escaped, bool escape_period)
static List * database_get_xml_visible_schemas(void)
static StringInfo schema_to_xml_internal(Oid nspid, const char *xmlschema, bool nulls, bool tableforest, const char *targetns, bool top_level)
References appendBinaryStringInfo(), appendStringInfo(), appendStringInfoChar(), StringInfoData::data, database_get_xml_visible_schemas(), get_database_name(), StringInfoData::len, lfirst_oid, makeStringInfo(), map_sql_identifier_to_xml_name(), MyDatabaseId, nspid, schema_to_xml_internal(), SPI_connect(), SPI_finish(), xmldata_root_element_end(), and xmldata_root_element_start().
Referenced by database_to_xml(), and database_to_xml_and_xmlschema().
◆ database_to_xmlschema()
◆ database_to_xmlschema_internal()
static StringInfo database_to_xmlschema_internal ( bool nulls, bool tableforest, const char * targetns ) | static |
---|
Definition at line 3422 of file xml.c.
3424{
3425 List *relid_list;
3426 List *nspid_list;
3427 List *tupdesc_list;
3430
3432
3434
3436
3439
3440 tupdesc_list = NIL;
3441 foreach(cell, relid_list)
3442 {
3444
3448 }
3449
3452
3455
3457
3459
3460 return result;
3461}
List * lappend(List *list, void *datum)
void appendStringInfoString(StringInfo str, const char *s)
void table_close(Relation relation, LOCKMODE lockmode)
Relation table_open(Oid relationId, LOCKMODE lockmode)
TupleDesc CreateTupleDescCopy(TupleDesc tupdesc)
static const char * map_sql_catalog_to_xmlschema_types(List *nspid_list, bool nulls, bool tableforest, const char *targetns)
static void xsd_schema_element_start(StringInfo result, const char *targetns)
static List * database_get_xml_visible_tables(void)
static const char * map_sql_typecoll_to_xmlschema_types(List *tupdesc_list)
static void xsd_schema_element_end(StringInfo result)
References AccessShareLock, appendStringInfoString(), CreateTupleDescCopy(), database_get_xml_visible_schemas(), database_get_xml_visible_tables(), lappend(), lfirst_oid, makeStringInfo(), map_sql_catalog_to_xmlschema_types(), map_sql_typecoll_to_xmlschema_types(), NIL, NoLock, RelationData::rd_att, SPI_connect(), SPI_finish(), table_close(), table_open(), xsd_schema_element_end(), and xsd_schema_element_start().
Referenced by database_to_xml_and_xmlschema(), and database_to_xmlschema().
◆ escape_xml()
char * escape_xml | ( | const char * | str | ) |
---|
◆ map_multipart_sql_identifier_to_xml_name()
static char * map_multipart_sql_identifier_to_xml_name ( const char * a, const char * b, const char * c, const char * d ) | static |
---|
◆ map_sql_catalog_to_xmlschema_types()
static const char * map_sql_catalog_to_xmlschema_types ( List * nspid_list, bool nulls, bool tableforest, const char * targetns ) | static |
---|
Definition at line 3705 of file xml.c.
3707{
3709 char *xmlcn;
3710 char *catalogtypename;
3713
3715
3717
3719
3722 NULL,
3723 NULL);
3724
3726 "<xsd:complexType name=\"%s\">\n", catalogtypename);
3728 " xsd:all\n");
3729
3730 foreach(cell, nspid_list)
3731 {
3737 nspname,
3738 NULL);
3739
3741 " <xsd:element name=\"%s\" type=\"%s\"/>\n",
3742 xmlsn, schematypename);
3743 }
3744
3746 " \n");
3748 "\n\n");
3749
3751 "<xsd:element name=\"%s\" type=\"%s\"/>\n\n",
3752 xmlcn, catalogtypename);
3753
3754 return result.data;
3755}
char * get_namespace_name(Oid nspid)
static char * map_multipart_sql_identifier_to_xml_name(const char *a, const char *b, const char *c, const char *d)
References appendStringInfo(), appendStringInfoString(), StringInfoData::data, dbname, get_database_name(), get_namespace_name(), initStringInfo(), lfirst_oid, map_multipart_sql_identifier_to_xml_name(), map_sql_identifier_to_xml_name(), MyDatabaseId, and nspid.
Referenced by database_to_xmlschema_internal().
◆ map_sql_identifier_to_xml_name()
char * map_sql_identifier_to_xml_name | ( | const char * | ident, |
---|---|---|---|
bool | fully_escaped, | ||
bool | escape_period | ||
) |
Definition at line 2391 of file xml.c.
2393{
2394#ifdef USE_LIBXML
2396 const char *p;
2397
2398
2399
2400
2401
2402 Assert(fully_escaped || !escape_period);
2403
2405
2407 {
2408 if (*p == ':' && (p == ident || fully_escaped))
2410 else if (*p == '_' && *(p + 1) == 'x')
2412 else if (fully_escaped && p == ident &&
2414 {
2415 if (*p == 'x')
2417 else
2419 }
2420 else if (escape_period && *p == '.')
2422 else
2423 {
2424 pg_wchar u = sqlchar_to_unicode(p);
2425
2426 if ((p == ident)
2427 ? !is_valid_xml_namefirst(u)
2428 : !is_valid_xml_namechar(u))
2430 else
2432 }
2433 }
2434
2435 return buf.data;
2436#else
2438 return NULL;
2439#endif
2440}
Assert(PointerIsAligned(start, uint64))
int pg_mblen(const char *mbstr)
int pg_strncasecmp(const char *s1, const char *s2, size_t n)
References appendBinaryStringInfo(), appendStringInfo(), appendStringInfoString(), Assert(), buf, ident, initStringInfo(), NO_XML_SUPPORT, pg_mblen(), and pg_strncasecmp().
Referenced by database_to_xml_internal(), map_multipart_sql_identifier_to_xml_name(), map_sql_catalog_to_xmlschema_types(), map_sql_schema_to_xmlschema_types(), map_sql_table_to_xmlschema(), query_to_xml_internal(), schema_to_xml_internal(), SPI_sql_row_to_xmlelement(), and transformXmlExpr().
◆ map_sql_schema_to_xmlschema_types()
static const char * map_sql_schema_to_xmlschema_types ( Oid nspid, List * relid_list, bool nulls, bool tableforest, const char * targetns ) | static |
---|
Definition at line 3632 of file xml.c.
3634{
3636 char *nspname;
3637 char *xmlsn;
3638 char *schematypename;
3641
3644
3646
3648
3651 nspname,
3652 NULL);
3653
3655 "<xsd:complexType name=\"%s\">\n", schematypename);
3656 if (!tableforest)
3658 " xsd:all\n");
3659 else
3661 " xsd:sequence\n");
3662
3663 foreach(cell, relid_list)
3664 {
3670 nspname,
3672
3673 if (!tableforest)
3675 " <xsd:element name=\"%s\" type=\"%s\"/>\n",
3676 xmltn, tabletypename);
3677 else
3679 " <xsd:element name=\"%s\" type=\"%s\" minOccurs=\"0\" maxOccurs=\"unbounded\"/>\n",
3680 xmltn, tabletypename);
3681 }
3682
3683 if (!tableforest)
3685 " \n");
3686 else
3688 " \n");
3690 "\n\n");
3691
3693 "<xsd:element name=\"%s\" type=\"%s\"/>\n\n",
3694 xmlsn, schematypename);
3695
3696 return result.data;
3697}
char * get_rel_name(Oid relid)
References appendStringInfo(), appendStringInfoString(), StringInfoData::data, dbname, get_database_name(), get_namespace_name(), get_rel_name(), initStringInfo(), lfirst_oid, map_multipart_sql_identifier_to_xml_name(), map_sql_identifier_to_xml_name(), MyDatabaseId, nspid, and relname.
Referenced by schema_to_xmlschema_internal().
◆ map_sql_table_to_xmlschema()
static const char * map_sql_table_to_xmlschema ( TupleDesc tupdesc, Oid relid, bool nulls, bool tableforest, const char * targetns ) | static |
---|
Definition at line 3527 of file xml.c.
3529{
3530 int i;
3531 char *xmltn;
3532 char *tabletypename;
3533 char *rowtypename;
3535
3537
3539 {
3542
3545 elog(ERROR, "cache lookup failed for relation %u", relid);
3547
3549 true, false);
3550
3554 NameStr(reltuple->relname));
3555
3559 NameStr(reltuple->relname));
3560
3562 }
3563 else
3564 {
3565 if (tableforest)
3566 xmltn = "row";
3567 else
3568 xmltn = "table";
3569
3570 tabletypename = "TableType";
3571 rowtypename = "RowType";
3572 }
3573
3575
3578
3580 "<xsd:complexType name=\"%s\">\n"
3581 " xsd:sequence\n",
3582 rowtypename);
3583
3584 for (i = 0; i < tupdesc->natts; i++)
3585 {
3587
3588 if (att->attisdropped)
3589 continue;
3591 " <xsd:element name=\"%s\" type=\"%s\"%s>\n",
3593 true, false),
3595 nulls ? " nillable=\"true\"" : " minOccurs=\"0\"");
3596 }
3597
3599 " \n"
3600 "\n\n");
3601
3602 if (!tableforest)
3603 {
3605 "<xsd:complexType name=\"%s\">\n"
3606 " xsd:sequence\n"
3607 " <xsd:element name=\"row\" type=\"%s\" minOccurs=\"0\" maxOccurs=\"unbounded\"/>\n"
3608 " \n"
3609 "\n\n",
3610 tabletypename, rowtypename);
3611
3613 "<xsd:element name=\"%s\" type=\"%s\"/>\n\n",
3614 xmltn, tabletypename);
3615 }
3616 else
3618 "<xsd:element name=\"%s\" type=\"%s\"/>\n\n",
3619 xmltn, rowtypename);
3620
3622
3623 return result.data;
3624}
#define OidIsValid(objectId)
#define HeapTupleIsValid(tuple)
static void * GETSTRUCT(const HeapTupleData *tuple)
FormData_pg_attribute * Form_pg_attribute
FormData_pg_class * Form_pg_class
static Datum ObjectIdGetDatum(Oid X)
void ReleaseSysCache(HeapTuple tuple)
HeapTuple SearchSysCache1(int cacheId, Datum key1)
static FormData_pg_attribute * TupleDescAttr(TupleDesc tupdesc, int i)
static const char * map_sql_type_to_xml_name(Oid typeoid, int typmod)
References appendStringInfo(), appendStringInfoString(), StringInfoData::data, elog, ERROR, get_database_name(), get_namespace_name(), GETSTRUCT(), HeapTupleIsValid, i, initStringInfo(), list_make1, map_multipart_sql_identifier_to_xml_name(), map_sql_identifier_to_xml_name(), map_sql_type_to_xml_name(), map_sql_typecoll_to_xmlschema_types(), MyDatabaseId, NameStr, TupleDescData::natts, ObjectIdGetDatum(), OidIsValid, ReleaseSysCache(), SearchSysCache1(), TupleDescAttr(), xsd_schema_element_end(), and xsd_schema_element_start().
Referenced by cursor_to_xmlschema(), query_to_xml_and_xmlschema(), query_to_xmlschema(), table_to_xml_and_xmlschema(), and table_to_xmlschema().
◆ map_sql_type_to_xml_name()
static const char * map_sql_type_to_xml_name ( Oid typeoid, int typmod ) | static |
---|
Definition at line 3762 of file xml.c.
3763{
3765
3767
3768 switch (typeoid)
3769 {
3770 case BPCHAROID:
3771 if (typmod == -1)
3773 else
3775 break;
3776 case VARCHAROID:
3777 if (typmod == -1)
3779 else
3781 break;
3782 case NUMERICOID:
3783 if (typmod == -1)
3785 else
3787 ((typmod - VARHDRSZ) >> 16) & 0xffff,
3788 (typmod - VARHDRSZ) & 0xffff);
3789 break;
3790 case INT4OID:
3792 break;
3793 case INT2OID:
3795 break;
3796 case INT8OID:
3798 break;
3799 case FLOAT4OID:
3801 break;
3802 case FLOAT8OID:
3804 break;
3805 case BOOLOID:
3807 break;
3808 case TIMEOID:
3809 if (typmod == -1)
3811 else
3813 break;
3814 case TIMETZOID:
3815 if (typmod == -1)
3817 else
3819 break;
3820 case TIMESTAMPOID:
3821 if (typmod == -1)
3823 else
3825 break;
3826 case TIMESTAMPTZOID:
3827 if (typmod == -1)
3829 else
3831 break;
3832 case DATEOID:
3834 break;
3835 case XMLOID:
3837 break;
3838 default:
3839 {
3842
3845 elog(ERROR, "cache lookup failed for type %u", typeoid);
3847
3852 NameStr(typtuple->typname)));
3853
3855 }
3856 }
3857
3858 return result.data;
3859}
FormData_pg_type * Form_pg_type
References appendStringInfo(), appendStringInfoString(), StringInfoData::data, elog, ERROR, get_database_name(), get_namespace_name(), GETSTRUCT(), HeapTupleIsValid, initStringInfo(), map_multipart_sql_identifier_to_xml_name(), MyDatabaseId, NameStr, ObjectIdGetDatum(), ReleaseSysCache(), SearchSysCache1(), and VARHDRSZ.
Referenced by map_sql_table_to_xmlschema(), and map_sql_type_to_xmlschema_type().
◆ map_sql_type_to_xmlschema_type()
static const char * map_sql_type_to_xmlschema_type ( Oid typeoid, int typmod ) | static |
---|
Definition at line 3922 of file xml.c.
3923{
3926
3928
3929 if (typeoid == XMLOID)
3930 {
3932 "<xsd:complexType mixed=\"true\">\n"
3933 " xsd:sequence\n"
3934 " <xsd:any name=\"element\" minOccurs=\"0\" maxOccurs=\"unbounded\" processContents=\"skip\"/>\n"
3935 " \n"
3936 "\n");
3937 }
3938 else
3939 {
3941 "<xsd:simpleType name=\"%s\">\n", typename);
3942
3943 switch (typeoid)
3944 {
3945 case BPCHAROID:
3946 case VARCHAROID:
3947 case TEXTOID:
3949 " <xsd:restriction base=\"xsd:string\">\n");
3950 if (typmod != -1)
3952 " <xsd:maxLength value=\"%d\"/>\n",
3955 break;
3956
3957 case BYTEAOID:
3959 " <xsd:restriction base=\"xsd:%s\">\n"
3960 " \n",
3962 break;
3963
3964 case NUMERICOID:
3965 if (typmod != -1)
3967 " <xsd:restriction base=\"xsd:decimal\">\n"
3968 " <xsd:totalDigits value=\"%d\"/>\n"
3969 " <xsd:fractionDigits value=\"%d\"/>\n"
3970 " \n",
3971 ((typmod - VARHDRSZ) >> 16) & 0xffff,
3972 (typmod - VARHDRSZ) & 0xffff);
3973 break;
3974
3975 case INT2OID:
3977 " <xsd:restriction base=\"xsd:short\">\n"
3978 " <xsd:maxInclusive value=\"%d\"/>\n"
3979 " <xsd:minInclusive value=\"%d\"/>\n"
3980 " \n",
3981 SHRT_MAX, SHRT_MIN);
3982 break;
3983
3984 case INT4OID:
3986 " <xsd:restriction base=\"xsd:int\">\n"
3987 " <xsd:maxInclusive value=\"%d\"/>\n"
3988 " <xsd:minInclusive value=\"%d\"/>\n"
3989 " \n",
3990 INT_MAX, INT_MIN);
3991 break;
3992
3993 case INT8OID:
3995 " <xsd:restriction base=\"xsd:long\">\n"
3996 " <xsd:maxInclusive value=\"" INT64_FORMAT "\"/>\n"
3997 " <xsd:minInclusive value=\"" INT64_FORMAT "\"/>\n"
3998 " \n",
4001 break;
4002
4003 case FLOAT4OID:
4005 " <xsd:restriction base=\"xsd:float\">\n");
4006 break;
4007
4008 case FLOAT8OID:
4010 " <xsd:restriction base=\"xsd:double\">\n");
4011 break;
4012
4013 case BOOLOID:
4015 " <xsd:restriction base=\"xsd:boolean\">\n");
4016 break;
4017
4018 case TIMEOID:
4019 case TIMETZOID:
4020 {
4021 const char *tz = (typeoid == TIMETZOID ? "(\\+|-)\\p{Nd}{2}:\\p{Nd}{2}" : "");
4022
4023 if (typmod == -1)
4025 " <xsd:restriction base=\"xsd:time\">\n"
4026 " <xsd:pattern value=\"\\p{Nd}{2}:\\p{Nd}{2}:\\p{Nd}{2}(.\\p{Nd}+)?%s\"/>\n"
4027 " \n", tz);
4028 else if (typmod == 0)
4030 " <xsd:restriction base=\"xsd:time\">\n"
4031 " <xsd:pattern value=\"\\p{Nd}{2}:\\p{Nd}{2}:\\p{Nd}{2}%s\"/>\n"
4032 " \n", tz);
4033 else
4035 " <xsd:restriction base=\"xsd:time\">\n"
4036 " <xsd:pattern value=\"\\p{Nd}{2}:\\p{Nd}{2}:\\p{Nd}{2}.\\p{Nd}{%d}%s\"/>\n"
4037 " \n", typmod - VARHDRSZ, tz);
4038 break;
4039 }
4040
4041 case TIMESTAMPOID:
4042 case TIMESTAMPTZOID:
4043 {
4044 const char *tz = (typeoid == TIMESTAMPTZOID ? "(\\+|-)\\p{Nd}{2}:\\p{Nd}{2}" : "");
4045
4046 if (typmod == -1)
4048 " <xsd:restriction base=\"xsd:dateTime\">\n"
4049 " <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"
4050 " \n", tz);
4051 else if (typmod == 0)
4053 " <xsd:restriction base=\"xsd:dateTime\">\n"
4054 " <xsd:pattern value=\"\\p{Nd}{4}-\\p{Nd}{2}-\\p{Nd}{2}T\\p{Nd}{2}:\\p{Nd}{2}:\\p{Nd}{2}%s\"/>\n"
4055 " \n", tz);
4056 else
4058 " <xsd:restriction base=\"xsd:dateTime\">\n"
4059 " <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"
4060 " \n", typmod - VARHDRSZ, tz);
4061 break;
4062 }
4063
4064 case DATEOID:
4066 " <xsd:restriction base=\"xsd:date\">\n"
4067 " <xsd:pattern value=\"\\p{Nd}{4}-\\p{Nd}{2}-\\p{Nd}{2}\"/>\n"
4068 " \n");
4069 break;
4070
4071 default:
4072 if (get_typtype(typeoid) == TYPTYPE_DOMAIN)
4073 {
4074 Oid base_typeoid;
4075 int32 base_typmod = -1;
4076
4078
4080 " <xsd:restriction base=\"%s\"/>\n",
4082 }
4083 break;
4084 }
4086 }
4087
4088 return result.data;
4089}
char get_typtype(Oid typid)
Oid getBaseTypeAndTypmod(Oid typid, int32 *typmod)
References appendStringInfo(), appendStringInfoString(), StringInfoData::data, get_typtype(), getBaseTypeAndTypmod(), initStringInfo(), INT64_FORMAT, map_sql_type_to_xml_name(), PG_INT64_MAX, PG_INT64_MIN, VARHDRSZ, xmlbinary, and XMLBINARY_BASE64.
Referenced by map_sql_typecoll_to_xmlschema_types().
◆ map_sql_typecoll_to_xmlschema_types()
static const char * map_sql_typecoll_to_xmlschema_types ( List * tupdesc_list) | static |
---|
Definition at line 3867 of file xml.c.
3868{
3870 int i;
3873
3874
3875 foreach(cell0, tupdesc_list)
3876 {
3878
3879 for (i = 0; i < tupdesc->natts; i++)
3880 {
3882
3883 if (att->attisdropped)
3884 continue;
3886 }
3887 }
3888
3889
3890 foreach(cell0, uniquetypes)
3891 {
3894
3895 if (basetypid != typid)
3897 }
3898
3899
3901
3902 foreach(cell0, uniquetypes)
3903 {
3906 -1));
3907 }
3908
3909 return result.data;
3910}
List * list_append_unique_oid(List *list, Oid datum)
Oid getBaseType(Oid typid)
struct TupleDescData * TupleDesc
static const char * map_sql_type_to_xmlschema_type(Oid typeoid, int typmod)
References appendStringInfo(), StringInfoData::data, getBaseType(), i, initStringInfo(), lfirst, lfirst_oid, list_append_unique_oid(), map_sql_type_to_xmlschema_type(), TupleDescData::natts, NIL, and TupleDescAttr().
Referenced by database_to_xmlschema_internal(), map_sql_table_to_xmlschema(), and schema_to_xmlschema_internal().
◆ map_sql_value_to_xml_value()
char * map_sql_value_to_xml_value | ( | Datum | value, |
---|---|---|---|
Oid | type, | ||
bool | xml_escape_strings | ||
) |
Definition at line 2489 of file xml.c.
2490{
2492 {
2494 Oid elmtype;
2496 bool elmbyval;
2497 char elmalign;
2498 int num_elems;
2499 Datum *elem_values;
2500 bool *elem_nulls;
2502 int i;
2503
2507
2509 elmlen, elmbyval, elmalign,
2510 &elem_values, &elem_nulls,
2511 &num_elems);
2512
2514
2515 for (i = 0; i < num_elems; i++)
2516 {
2517 if (elem_nulls[i])
2518 continue;
2522 elmtype, true));
2524 }
2525
2526 pfree(elem_values);
2527 pfree(elem_nulls);
2528
2529 return buf.data;
2530 }
2531 else
2532 {
2533 Oid typeOut;
2534 bool isvarlena;
2535 char *str;
2536
2537
2538
2539
2540
2542
2543
2544
2545
2546 switch (type)
2547 {
2548 case BOOLOID:
2550 return "true";
2551 else
2552 return "false";
2553
2554 case DATEOID:
2555 {
2559
2561
2564 (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
2565 errmsg("date out of range"),
2566 errdetail("XML does not support infinite date values.")));
2570
2572 }
2573
2574 case TIMESTAMPOID:
2575 {
2580
2582
2583
2586 (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
2587 errmsg("timestamp out of range"),
2588 errdetail("XML does not support infinite timestamp values.")));
2591 else
2593 (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
2594 errmsg("timestamp out of range")));
2595
2597 }
2598
2599 case TIMESTAMPTZOID:
2600 {
2603 int tz;
2605 const char *tzn = NULL;
2607
2609
2610
2613 (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
2614 errmsg("timestamp out of range"),
2615 errdetail("XML does not support infinite timestamp values.")));
2618 else
2620 (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
2621 errmsg("timestamp out of range")));
2622
2624 }
2625
2626#ifdef USE_LIBXML
2627 case BYTEAOID:
2628 {
2631 volatile xmlBufferPtr buf = NULL;
2632 volatile xmlTextWriterPtr writer = NULL;
2633 char *result;
2634
2636
2638 {
2639 buf = xmlBufferCreate();
2640 if (buf == NULL || xmlerrcxt->err_occurred)
2642 "could not allocate xmlBuffer");
2643 writer = xmlNewTextWriterMemory(buf, 0);
2644 if (writer == NULL || xmlerrcxt->err_occurred)
2646 "could not allocate xmlTextWriter");
2647
2649 xmlTextWriterWriteBase64(writer, VARDATA_ANY(bstr),
2651 else
2652 xmlTextWriterWriteBinHex(writer, VARDATA_ANY(bstr),
2654
2655
2656 xmlFreeTextWriter(writer);
2657 writer = NULL;
2658
2659 result = pstrdup((const char *) xmlBufferContent(buf));
2660 }
2662 {
2663 if (writer)
2664 xmlFreeTextWriter(writer);
2665 if (buf)
2666 xmlBufferFree(buf);
2667
2669
2671 }
2673
2674 xmlBufferFree(buf);
2675
2677
2678 return result;
2679 }
2680#endif
2681
2682 }
2683
2684
2685
2686
2689
2690
2691 if (type == XMLOID || !xml_escape_strings)
2692 return str;
2693
2694
2696 }
2697}
#define DatumGetArrayTypeP(X)
void deconstruct_array(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 TIMESTAMP_NOT_FINITE(j)
#define POSTGRES_EPOCH_JDATE
#define DATE_NOT_FINITE(j)
static DateADT DatumGetDateADT(Datum X)
char * OidOutputFunctionCall(Oid functionId, Datum val)
#define DatumGetByteaPP(X)
void getTypeOutputInfo(Oid type, Oid *typOutput, bool *typIsVarlena)
void get_typlenbyvalalign(Oid typid, int16 *typlen, bool *typbyval, char *typalign)
#define type_is_array_domain(typid)
char * pstrdup(const char *in)
void pfree(void *pointer)
static bool DatumGetBool(Datum X)
static Timestamp DatumGetTimestamp(Datum X)
#define VARSIZE_ANY_EXHDR(PTR)
char * map_sql_value_to_xml_value(Datum value, Oid type, bool xml_escape_strings)
char * escape_xml(const char *str)
struct PgXmlErrorContext PgXmlErrorContext
PgXmlErrorContext * pg_xml_init(PgXmlStrictness strictness)
void xml_ereport(PgXmlErrorContext *errcxt, int level, int sqlcode, const char *msg)
void pg_xml_done(PgXmlErrorContext *errcxt, bool isError)
References appendStringInfoString(), ARR_ELEMTYPE, buf, DATE_NOT_FINITE, DatumGetArrayTypeP, DatumGetBool(), DatumGetByteaPP, DatumGetDateADT(), DatumGetTimestamp(), deconstruct_array(), EncodeDateOnly(), EncodeDateTime(), ereport, errcode(), errdetail(), errmsg(), ERROR, escape_xml(), get_typlenbyvalalign(), getBaseType(), getTypeOutputInfo(), i, initStringInfo(), j2date(), map_sql_value_to_xml_value(), MAXDATELEN, OidOutputFunctionCall(), pfree(), PG_CATCH, PG_END_TRY, PG_RE_THROW, PG_TRY, pg_xml_done(), pg_xml_init(), PG_XML_STRICTNESS_ALL, POSTGRES_EPOCH_JDATE, pstrdup(), str, timestamp2tm(), TIMESTAMP_NOT_FINITE, tm, pg_tm::tm_mday, pg_tm::tm_mon, pg_tm::tm_year, type, type_is_array_domain, USE_XSD_DATES, value, VARDATA_ANY, VARSIZE_ANY_EXHDR, xml_ereport(), xmlbinary, and XMLBINARY_BASE64.
Referenced by ExecEvalXmlExpr(), map_sql_value_to_xml_value(), SPI_sql_row_to_xmlelement(), and xmlelement().
◆ map_xml_name_to_sql_identifier()
char * map_xml_name_to_sql_identifier | ( | const char * | name | ) |
---|
Definition at line 2447 of file xml.c.
2448{
2450 const char *p;
2451
2453
2455 {
2456 if (*p == '_' && *(p + 1) == 'x'
2457 && isxdigit((unsigned char) *(p + 2))
2458 && isxdigit((unsigned char) *(p + 3))
2459 && isxdigit((unsigned char) *(p + 4))
2460 && isxdigit((unsigned char) *(p + 5))
2461 && *(p + 6) == '_')
2462 {
2464 unsigned int u;
2465
2466 sscanf(p + 2, "%X", &u);
2469 p += 6;
2470 }
2471 else
2473 }
2474
2475 return buf.data;
2476}
void pg_unicode_to_server(pg_wchar c, unsigned char *s)
#define MAX_UNICODE_EQUIVALENT_STRING
References appendBinaryStringInfo(), appendStringInfoString(), buf, initStringInfo(), MAX_UNICODE_EQUIVALENT_STRING, name, pg_mblen(), and pg_unicode_to_server().
Referenced by get_rule_expr().
◆ query_to_oid_list()
static List * query_to_oid_list ( const char * query) | static |
---|
Definition at line 2797 of file xml.c.
2798{
2801 int spi_result;
2802
2803 spi_result = SPI_execute(query, true, 0);
2805 elog(ERROR, "SPI_execute returned %s for %s",
2807
2809 {
2811 bool isnull;
2812
2815 1,
2816 &isnull);
2817 if (!isnull)
2819 }
2820
2821 return list;
2822}
List * lappend_oid(List *list, Oid datum)
static Oid DatumGetObjectId(Datum X)
const char * SPI_result_code_string(int code)
SPITupleTable * SPI_tuptable
int SPI_execute(const char *src, bool read_only, long tcount)
Datum SPI_getbinval(HeapTuple tuple, TupleDesc tupdesc, int fnumber, bool *isnull)
References DatumGetObjectId(), elog, ERROR, i, lappend_oid(), sort-test::list, NIL, SPI_execute(), SPI_getbinval(), SPI_OK_SELECT, SPI_processed, SPI_result_code_string(), SPI_tuptable, SPITupleTable::tupdesc, and SPITupleTable::vals.
Referenced by database_get_xml_visible_schemas(), database_get_xml_visible_tables(), and schema_get_xml_visible_tables().
◆ query_to_xml()
Definition at line 2910 of file xml.c.
2911{
2916
2918 NULL, nulls, tableforest,
2919 targetns, true)));
2920}
static StringInfo query_to_xml_internal(const char *query, char *tablename, const char *xmlschema, bool nulls, bool tableforest, const char *targetns, bool top_level)
References PG_GETARG_BOOL, PG_GETARG_TEXT_PP, PG_RETURN_XML_P, query_to_xml_internal(), stringinfo_to_xmltype(), and text_to_cstring().
◆ query_to_xml_and_xmlschema()
Definition at line 3156 of file xml.c.
3157{
3162
3163 const char *xmlschema;
3166
3168
3170 elog(ERROR, "SPI_prepare(\"%s\") failed", query);
3171
3173 elog(ERROR, "SPI_cursor_open(\"%s\") failed", query);
3174
3176 InvalidOid, nulls, tableforest, targetns));
3179
3181 xmlschema, nulls, tableforest,
3182 targetns, true)));
3183}
Portal SPI_cursor_open(const char *name, SPIPlanPtr plan, Datum *Values, const char *Nulls, bool read_only)
SPIPlanPtr SPI_prepare(const char *src, int nargs, Oid *argtypes)
void SPI_cursor_close(Portal portal)
References _SPI_strdup(), elog, ERROR, InvalidOid, map_sql_table_to_xmlschema(), PG_GETARG_BOOL, PG_GETARG_TEXT_PP, PG_RETURN_XML_P, plan, query_to_xml_internal(), SPI_connect(), SPI_cursor_close(), SPI_cursor_open(), SPI_finish(), SPI_prepare(), stringinfo_to_xmltype(), text_to_cstring(), and PortalData::tupDesc.
◆ query_to_xml_internal()
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 |
---|
Definition at line 3012 of file xml.c.
3015{
3017 char *xmltn;
3019
3020 if (tablename)
3022 else
3023 xmltn = "table";
3024
3026
3030 (errcode(ERRCODE_DATA_EXCEPTION),
3031 errmsg("invalid query")));
3032
3033 if (!tableforest)
3034 {
3036 targetns, top_level);
3038 }
3039
3040 if (xmlschema)
3042
3045 tableforest, targetns, top_level);
3046
3047 if (!tableforest)
3049
3051
3052 return result;
3053}
References appendStringInfo(), appendStringInfoChar(), ereport, errcode(), errmsg(), ERROR, i, makeStringInfo(), map_sql_identifier_to_xml_name(), SPI_connect(), SPI_execute(), SPI_finish(), SPI_OK_SELECT, SPI_processed, SPI_sql_row_to_xmlelement(), xmldata_root_element_end(), and xmldata_root_element_start().
Referenced by query_to_xml(), query_to_xml_and_xmlschema(), and table_to_xml_internal().
◆ query_to_xmlschema()
Definition at line 3076 of file xml.c.
3077{
3082 const char *result;
3085
3087
3089 elog(ERROR, "SPI_prepare(\"%s\") failed", query);
3090
3092 elog(ERROR, "SPI_cursor_open(\"%s\") failed", query);
3093
3096 tableforest, targetns));
3099
3101}
References _SPI_strdup(), cstring_to_xmltype(), elog, ERROR, InvalidOid, map_sql_table_to_xmlschema(), PG_GETARG_BOOL, PG_GETARG_TEXT_PP, PG_RETURN_XML_P, plan, SPI_connect(), SPI_cursor_close(), SPI_cursor_open(), SPI_finish(), SPI_prepare(), text_to_cstring(), and PortalData::tupDesc.
◆ schema_get_xml_visible_tables()
static List * schema_get_xml_visible_tables ( Oid nspid) | static |
---|
◆ schema_to_xml()
Definition at line 3235 of file xml.c.
3236{
3241
3242 char *schemaname;
3244
3247
3249 nulls, tableforest, targetns, true)));
3250}
#define PG_GETARG_NAME(n)
Oid LookupExplicitNamespace(const char *nspname, bool missing_ok)
References LookupExplicitNamespace(), name, NameStr, nspid, PG_GETARG_BOOL, PG_GETARG_NAME, PG_GETARG_TEXT_PP, PG_RETURN_XML_P, schema_to_xml_internal(), stringinfo_to_xmltype(), and text_to_cstring().
◆ schema_to_xml_and_xmlschema()
Definition at line 3339 of file xml.c.
3340{
3345 char *schemaname;
3348
3351
3353 tableforest, targetns);
3354
3356 xmlschema->data, nulls,
3357 tableforest, targetns, true)));
3358}
static StringInfo schema_to_xmlschema_internal(const char *schemaname, bool nulls, bool tableforest, const char *targetns)
References StringInfoData::data, LookupExplicitNamespace(), name, NameStr, nspid, PG_GETARG_BOOL, PG_GETARG_NAME, PG_GETARG_TEXT_PP, PG_RETURN_XML_P, schema_to_xml_internal(), schema_to_xmlschema_internal(), stringinfo_to_xmltype(), and text_to_cstring().
◆ schema_to_xml_internal()
static StringInfo schema_to_xml_internal ( Oid nspid, const char * xmlschema, bool nulls, bool tableforest, const char * targetns, bool top_level ) | static |
---|
Definition at line 3192 of file xml.c.
3194{
3196 char *xmlsn;
3197 List *relid_list;
3199
3201 true, false);
3203
3206
3207 if (xmlschema)
3209
3211
3213
3214 foreach(cell, relid_list)
3215 {
3218
3220 targetns, false);
3221
3224 }
3225
3227
3229
3230 return result;
3231}
static List * schema_get_xml_visible_tables(Oid nspid)
static StringInfo table_to_xml_internal(Oid relid, const char *xmlschema, bool nulls, bool tableforest, const char *targetns, bool top_level)
References appendBinaryStringInfo(), appendStringInfo(), appendStringInfoChar(), StringInfoData::data, get_namespace_name(), StringInfoData::len, lfirst_oid, makeStringInfo(), map_sql_identifier_to_xml_name(), nspid, schema_get_xml_visible_tables(), SPI_connect(), SPI_finish(), table_to_xml_internal(), xmldata_root_element_end(), and xmldata_root_element_start().
Referenced by database_to_xml_internal(), schema_to_xml(), and schema_to_xml_and_xmlschema().
◆ schema_to_xmlschema()
Definition at line 3326 of file xml.c.
3327{
3332
3334 nulls, tableforest, targetns)));
3335}
References name, NameStr, PG_GETARG_BOOL, PG_GETARG_NAME, PG_GETARG_TEXT_PP, PG_RETURN_XML_P, schema_to_xmlschema_internal(), stringinfo_to_xmltype(), and text_to_cstring().
◆ schema_to_xmlschema_internal()
static StringInfo schema_to_xmlschema_internal ( const char * schemaname, bool nulls, bool tableforest, const char * targetns ) | static |
---|
Definition at line 3281 of file xml.c.
3283{
3285 List *relid_list;
3286 List *tupdesc_list;
3289
3291
3293
3295
3297
3299
3300 tupdesc_list = NIL;
3301 foreach(cell, relid_list)
3302 {
3304
3308 }
3309
3312
3315 nulls, tableforest, targetns));
3316
3318
3320
3321 return result;
3322}
static const char * map_sql_schema_to_xmlschema_types(Oid nspid, List *relid_list, bool nulls, bool tableforest, const char *targetns)
References AccessShareLock, appendStringInfoString(), CreateTupleDescCopy(), lappend(), lfirst_oid, LookupExplicitNamespace(), makeStringInfo(), map_sql_schema_to_xmlschema_types(), map_sql_typecoll_to_xmlschema_types(), NIL, NoLock, nspid, RelationData::rd_att, schema_get_xml_visible_tables(), SPI_connect(), SPI_finish(), table_close(), table_open(), xsd_schema_element_end(), and xsd_schema_element_start().
Referenced by schema_to_xml_and_xmlschema(), and schema_to_xmlschema().
◆ SPI_sql_row_to_xmlelement()
static void SPI_sql_row_to_xmlelement ( uint64 rownum, StringInfo result, char * tablename, bool nulls, bool tableforest, const char * targetns, bool top_level ) | static |
---|
Definition at line 4097 of file xml.c.
4100{
4101 int i;
4102 char *xmltn;
4103
4104 if (tablename)
4106 else
4107 {
4108 if (tableforest)
4109 xmltn = "row";
4110 else
4111 xmltn = "table";
4112 }
4113
4114 if (tableforest)
4116 else
4118
4120 {
4121 char *colname;
4123 bool isnull;
4124
4126 true, false);
4129 i,
4130 &isnull);
4131 if (isnull)
4132 {
4133 if (nulls)
4134 appendStringInfo(result, " <%s xsi:nil=\"true\"/>\n", colname);
4135 }
4136 else
4138 colname,
4141 colname);
4142 }
4143
4144 if (tableforest)
4145 {
4148 }
4149 else
4151}
Oid SPI_gettypeid(TupleDesc tupdesc, int fnumber)
char * SPI_fname(TupleDesc tupdesc, int fnumber)
References appendStringInfo(), appendStringInfoChar(), appendStringInfoString(), i, map_sql_identifier_to_xml_name(), map_sql_value_to_xml_value(), TupleDescData::natts, SPI_fname(), SPI_getbinval(), SPI_gettypeid(), SPI_tuptable, SPITupleTable::tupdesc, SPITupleTable::vals, xmldata_root_element_end(), and xmldata_root_element_start().
Referenced by cursor_to_xml(), and query_to_xml_internal().
◆ stringinfo_to_xmltype()
Definition at line 467 of file xml.c.
468{
470}
text * cstring_to_text_with_len(const char *s, int len)
References buf, and cstring_to_text_with_len().
Referenced by cursor_to_xml(), database_to_xml(), database_to_xml_and_xmlschema(), database_to_xmlschema(), query_to_xml(), query_to_xml_and_xmlschema(), schema_to_xml(), schema_to_xml_and_xmlschema(), schema_to_xmlschema(), table_to_xml(), table_to_xml_and_xmlschema(), xmlcomment(), xmlconcat(), xmlpi(), and xmlroot().
◆ table_to_xml()
◆ table_to_xml_and_xmlschema()
Definition at line 3135 of file xml.c.
3136{
3142 const char *xmlschema;
3143
3146 tableforest, targetns);
3148
3150 xmlschema, nulls, tableforest,
3151 targetns, true)));
3152}
References AccessShareLock, map_sql_table_to_xmlschema(), NoLock, PG_GETARG_BOOL, PG_GETARG_OID, PG_GETARG_TEXT_PP, PG_RETURN_XML_P, RelationData::rd_att, stringinfo_to_xmltype(), table_close(), table_open(), table_to_xml_internal(), and text_to_cstring().
◆ table_to_xml_internal()
static StringInfo table_to_xml_internal ( Oid relid, const char * xmlschema, bool nulls, bool tableforest, const char * targetns, bool top_level ) | static |
---|
Definition at line 2879 of file xml.c.
2882{
2884
2890 xmlschema, nulls, tableforest,
2891 targetns, top_level);
2892}
#define DirectFunctionCall1(func, arg1)
static char * DatumGetCString(Datum X)
Datum regclassout(PG_FUNCTION_ARGS)
References appendStringInfo(), StringInfoData::data, DatumGetCString(), DirectFunctionCall1, get_rel_name(), initStringInfo(), ObjectIdGetDatum(), query_to_xml_internal(), and regclassout().
Referenced by schema_to_xml_internal(), table_to_xml(), and table_to_xml_and_xmlschema().
◆ table_to_xmlschema()
Definition at line 3057 of file xml.c.
3058{
3063 const char *result;
3065
3068 tableforest, targetns);
3070
3072}
References AccessShareLock, cstring_to_xmltype(), map_sql_table_to_xmlschema(), NoLock, PG_GETARG_BOOL, PG_GETARG_OID, PG_GETARG_TEXT_PP, PG_RETURN_XML_P, RelationData::rd_att, table_close(), table_open(), and text_to_cstring().
◆ texttoxml()
◆ xml_in()
◆ xml_is_document()
bool xml_is_document | ( | xmltype * | arg | ) |
---|
◆ xml_is_well_formed()
◆ xml_is_well_formed_content()
◆ xml_is_well_formed_document()
◆ xml_out()
◆ xml_out_internal()
static char * xml_out_internal ( xmltype * x, pg_enc target_encoding ) | static |
---|
Definition at line 312 of file xml.c.
313{
315
316#ifdef USE_LIBXML
318 xmlChar *version;
319 int standalone;
320 int res_code;
321
322 if ((res_code = parse_xml_decl((xmlChar *) str,
323 &len, &version, NULL, &standalone)) == 0)
324 {
326
328
329 if (!print_xml_decl(&buf, version, target_encoding, standalone))
330 {
331
332
333
334
335
337 len += 1;
338 }
340
342
343 return buf.data;
344 }
345
348 errmsg_internal("could not parse XML declaration in stored value"),
349 errdetail_for_xml_code(res_code));
350#endif
351 return str;
352}
int errmsg_internal(const char *fmt,...)
#define ERRCODE_DATA_CORRUPTED
References appendStringInfoString(), buf, ereport, errcode(), ERRCODE_DATA_CORRUPTED, errmsg_internal(), initStringInfo(), len, pfree(), str, text_to_cstring(), WARNING, and x.
Referenced by xml_out(), xml_send(), and XmlTableSetDocument().
◆ xml_recv()
Definition at line 371 of file xml.c.
372{
373#ifdef USE_LIBXML
376 char *str;
377 char *newstr;
378 int nbytes;
379 xmlDocPtr doc;
380 xmlChar *encodingStr = NULL;
382
383
384
385
386
387
388 nbytes = buf->len - buf->cursor;
390
391
392
393
394
395
398 memcpy(VARDATA(result), str, nbytes);
400 str[nbytes] = '\0';
401
402 parse_xml_decl((const xmlChar *) str, NULL, NULL, &encodingStr, NULL);
403
404
405
406
407
408
409
410 encoding = encodingStr ? xmlChar_to_encoding(encodingStr) : PG_UTF8;
411
412
413
414
415
416 doc = xml_parse(result, xmloption, true, encoding, NULL, NULL, NULL);
417 xmlFreeDoc(doc);
418
419
421
422 if (newstr != str)
423 {
427 }
428
430#else
432 return 0;
433#endif
434}
#define PG_GETARG_POINTER(n)
char * pg_any_to_server(const char *s, int len, int encoding)
const char * pq_getmsgbytes(StringInfo msg, int datalen)
StringInfoData * StringInfo
#define SET_VARSIZE(PTR, len)
References buf, cstring_to_text(), encoding, NO_XML_SUPPORT, palloc(), pfree(), pg_any_to_server(), PG_GETARG_POINTER, PG_RETURN_XML_P, PG_UTF8, pq_getmsgbytes(), SET_VARSIZE, str, VARDATA, VARHDRSZ, and xmloption.
◆ xml_send()
Definition at line 438 of file xml.c.
439{
441 char *outval;
443
444
445
446
447
449
454}
#define PG_RETURN_BYTEA_P(x)
int pg_get_client_encoding(void)
void pq_sendtext(StringInfo buf, const char *str, int slen)
void pq_begintypsend(StringInfo buf)
bytea * pq_endtypsend(StringInfo buf)
References buf, pfree(), pg_get_client_encoding(), PG_GETARG_XML_P, PG_RETURN_BYTEA_P, pq_begintypsend(), pq_endtypsend(), pq_sendtext(), x, and xml_out_internal().
◆ xmlcomment()
Definition at line 491 of file xml.c.
492{
493#ifdef USE_LIBXML
498 int i;
499
500
502 {
503 if (argdata[i] == '-' && argdata[i - 1] == '-')
505 (errcode(ERRCODE_INVALID_XML_COMMENT),
506 errmsg("invalid XML comment")));
507 }
508 if (len > 0 && argdata[len - 1] == '-')
510 (errcode(ERRCODE_INVALID_XML_COMMENT),
511 errmsg("invalid XML comment")));
512
517
519#else
521 return 0;
522#endif
523}
static void appendStringInfoText(StringInfo str, const text *t)
References appendStringInfoString(), appendStringInfoText(), arg, buf, ereport, errcode(), errmsg(), ERROR, i, initStringInfo(), len, NO_XML_SUPPORT, PG_GETARG_TEXT_PP, PG_RETURN_XML_P, stringinfo_to_xmltype(), VARDATA_ANY, and VARSIZE_ANY_EXHDR.
◆ xmlconcat()
Definition at line 553 of file xml.c.
554{
555#ifdef USE_LIBXML
556 int global_standalone = 1;
557 xmlChar *global_version = NULL;
558 bool global_version_no_value = false;
561
563 foreach(v, args)
564 {
566 size_t len;
567 xmlChar *version;
568 int standalone;
569 char *str;
570
573
574 parse_xml_decl((xmlChar *) str, &len, &version, NULL, &standalone);
575
576 if (standalone == 0 && global_standalone == 1)
577 global_standalone = 0;
578 if (standalone < 0)
579 global_standalone = -1;
580
581 if (!version)
582 global_version_no_value = true;
583 else if (!global_version)
584 global_version = version;
585 else if (xmlStrcmp(version, global_version) != 0)
586 global_version_no_value = true;
587
590 }
591
592 if (!global_version_no_value || global_standalone >= 0)
593 {
595
597
598 print_xml_decl(&buf2,
599 (!global_version_no_value) ? global_version : NULL,
600 0,
601 global_standalone);
602
604 buf = buf2;
605 }
606
608#else
610 return NULL;
611#endif
612}
static Datum PointerGetDatum(const void *X)
static xmltype * DatumGetXmlP(Datum X)
References appendBinaryStringInfo(), appendStringInfoString(), generate_unaccent_rules::args, buf, DatumGetXmlP(), initStringInfo(), len, lfirst, NO_XML_SUPPORT, pfree(), PointerGetDatum(), str, stringinfo_to_xmltype(), text_to_cstring(), VARHDRSZ, VARSIZE, and x.
Referenced by ExecEvalXmlExpr(), and xmlconcat2().
◆ xmlconcat2()
◆ xmldata_root_element_end()
static void xmldata_root_element_end ( StringInfo result, const char * eltname ) | static |
---|
◆ xmldata_root_element_start()
static void xmldata_root_element_start ( StringInfo result, const char * eltname, const char * xmlschema, const char * targetns, bool top_level ) | static |
---|
◆ xmlelement()
xmltype * xmlelement | ( | XmlExpr * | xexpr, |
---|---|---|---|
Datum * | named_argvalue, | ||
bool * | named_argnull, | ||
Datum * | argvalue, | ||
bool * | argnull | ||
) |
Definition at line 864 of file xml.c.
867{
868#ifdef USE_LIBXML
870 List *named_arg_strings;
871 List *arg_strings;
872 int i;
876 volatile xmlBufferPtr buf = NULL;
877 volatile xmlTextWriterPtr writer = NULL;
878
879
880
881
882
883
884
885
886 named_arg_strings = NIL;
887 i = 0;
889 {
891 char *str;
892
893 if (named_argnull[i])
894 str = NULL;
895 else
898 false);
899 named_arg_strings = lappend(named_arg_strings, str);
900 i++;
901 }
902
903 arg_strings = NIL;
904 i = 0;
906 {
908 char *str;
909
910
911 if (!argnull[i])
912 {
915 true);
916 arg_strings = lappend(arg_strings, str);
917 }
918 i++;
919 }
920
922
924 {
925 buf = xmlBufferCreate();
926 if (buf == NULL || xmlerrcxt->err_occurred)
928 "could not allocate xmlBuffer");
929 writer = xmlNewTextWriterMemory(buf, 0);
930 if (writer == NULL || xmlerrcxt->err_occurred)
932 "could not allocate xmlTextWriter");
933
934 xmlTextWriterStartElement(writer, (xmlChar *) xexpr->name);
935
936 forboth(arg, named_arg_strings, narg, xexpr->arg_names)
937 {
940
942 xmlTextWriterWriteAttribute(writer,
943 (xmlChar *) argname,
944 (xmlChar *) str);
945 }
946
947 foreach(arg, arg_strings)
948 {
950
951 xmlTextWriterWriteRaw(writer, (xmlChar *) str);
952 }
953
954 xmlTextWriterEndElement(writer);
955
956
957 xmlFreeTextWriter(writer);
958 writer = NULL;
959
960 result = xmlBuffer_to_xmltype(buf);
961 }
963 {
964 if (writer)
965 xmlFreeTextWriter(writer);
967 xmlBufferFree(buf);
968
970
972 }
974
975 xmlBufferFree(buf);
976
978
979 return result;
980#else
982 return NULL;
983#endif
984}
Oid exprType(const Node *expr)
#define forboth(cell1, list1, cell2, list2)
References arg, XmlExpr::args, buf, ERROR, exprType(), forboth, i, lappend(), lfirst, map_sql_value_to_xml_value(), XmlExpr::named_args, NIL, NO_XML_SUPPORT, PG_CATCH, PG_END_TRY, PG_RE_THROW, PG_TRY, pg_xml_done(), pg_xml_init(), PG_XML_STRICTNESS_ALL, str, strVal, and xml_ereport().
Referenced by ExecEvalXmlExpr().
◆ xmlexists()
◆ xmlparse()
◆ xmlpi()
xmltype * xmlpi | ( | const char * | target, |
---|---|---|---|
text * | arg, | ||
bool | arg_is_null, | ||
bool * | result_is_null | ||
) |
Definition at line 1006 of file xml.c.
1007{
1008#ifdef USE_LIBXML
1011
1014 (errcode(ERRCODE_INVALID_XML_PROCESSING_INSTRUCTION),
1015 errmsg("invalid XML processing instruction"),
1016 errdetail("XML processing instruction target name cannot be \"%s\".", target)));
1017
1018
1019
1020
1021
1022 *result_is_null = arg_is_null;
1023 if (*result_is_null)
1024 return NULL;
1025
1027
1029
1030 if (arg != NULL)
1031 {
1033
1035 if (strstr(string, "?>") != NULL)
1037 (errcode(ERRCODE_INVALID_XML_PROCESSING_INSTRUCTION),
1038 errmsg("invalid XML processing instruction"),
1039 errdetail("XML processing instruction cannot contain \"?>\".")));
1040
1044 }
1046
1049 return result;
1050#else
1052 return NULL;
1053#endif
1054}
int pg_strcasecmp(const char *s1, const char *s2)
References appendStringInfo(), appendStringInfoChar(), appendStringInfoString(), arg, buf, ereport, errcode(), errdetail(), errmsg(), ERROR, initStringInfo(), NO_XML_SUPPORT, pfree(), pg_strcasecmp(), stringinfo_to_xmltype(), and text_to_cstring().
Referenced by ExecEvalXmlExpr().
◆ xmlroot()
Definition at line 1058 of file xml.c.
1059{
1060#ifdef USE_LIBXML
1061 char *str;
1062 size_t len;
1063 xmlChar *orig_version;
1064 int orig_standalone;
1066
1069
1070 parse_xml_decl((xmlChar *) str, &len, &orig_version, NULL, &orig_standalone);
1071
1072 if (version)
1073 orig_version = xml_text2xmlChar(version);
1074 else
1075 orig_version = NULL;
1076
1077 switch (standalone)
1078 {
1080 orig_standalone = 1;
1081 break;
1083 orig_standalone = 0;
1084 break;
1086 orig_standalone = -1;
1087 break;
1089
1090 break;
1091 }
1092
1094 print_xml_decl(&buf, orig_version, 0, orig_standalone);
1096
1098#else
1100 return NULL;
1101#endif
1102}
@ XML_STANDALONE_NO_VALUE
References appendStringInfoString(), buf, data, initStringInfo(), len, NO_XML_SUPPORT, str, stringinfo_to_xmltype(), text_to_cstring(), VARHDRSZ, VARSIZE, XML_STANDALONE_NO, XML_STANDALONE_NO_VALUE, XML_STANDALONE_OMITTED, and XML_STANDALONE_YES.
Referenced by ExecEvalXmlExpr().
◆ XmlTableDestroyOpaque()
Definition at line 5090 of file xml.c.
5091{
5092#ifdef USE_LIBXML
5093 XmlTableBuilderData *xtCxt;
5094
5095 xtCxt = GetXmlTableBuilderPrivateData(state, "XmlTableDestroyOpaque");
5096
5097
5098 xmlSetStructuredErrorFunc(xtCxt->xmlerrcxt, xml_errorHandler);
5099
5100 if (xtCxt->xpathscomp != NULL)
5101 {
5102 int i;
5103
5104 for (i = 0; i < xtCxt->natts; i++)
5105 if (xtCxt->xpathscomp[i] != NULL)
5106 xmlXPathFreeCompExpr(xtCxt->xpathscomp[i]);
5107 }
5108
5109 if (xtCxt->xpathobj != NULL)
5110 xmlXPathFreeObject(xtCxt->xpathobj);
5111 if (xtCxt->xpathcomp != NULL)
5112 xmlXPathFreeCompExpr(xtCxt->xpathcomp);
5113 if (xtCxt->xpathcxt != NULL)
5114 xmlXPathFreeContext(xtCxt->xpathcxt);
5115 if (xtCxt->doc != NULL)
5116 xmlFreeDoc(xtCxt->doc);
5117 if (xtCxt->ctxt != NULL)
5118 xmlFreeParserCtxt(xtCxt->ctxt);
5119
5121
5122
5123 xtCxt->magic = 0;
5124 state->opaque = NULL;
5125
5126#else
5128#endif
5129}
References i, NO_XML_SUPPORT, and pg_xml_done().
◆ XmlTableFetchRow()
Definition at line 4893 of file xml.c.
4894{
4895#ifdef USE_LIBXML
4896 XmlTableBuilderData *xtCxt;
4897
4898 xtCxt = GetXmlTableBuilderPrivateData(state, "XmlTableFetchRow");
4899
4900
4901 xmlSetStructuredErrorFunc(xtCxt->xmlerrcxt, xml_errorHandler);
4902
4903 if (xtCxt->xpathobj == NULL)
4904 {
4905 xtCxt->xpathobj = xmlXPathCompiledEval(xtCxt->xpathcomp, xtCxt->xpathcxt);
4906 if (xtCxt->xpathobj == NULL || xtCxt->xmlerrcxt->err_occurred)
4907 xml_ereport(xtCxt->xmlerrcxt, ERROR, ERRCODE_INVALID_ARGUMENT_FOR_XQUERY,
4908 "could not create XPath object");
4909
4910 xtCxt->row_count = 0;
4911 }
4912
4913 if (xtCxt->xpathobj->type == XPATH_NODESET)
4914 {
4915 if (xtCxt->xpathobj->nodesetval != NULL)
4916 {
4917 if (xtCxt->row_count++ < xtCxt->xpathobj->nodesetval->nodeNr)
4918 return true;
4919 }
4920 }
4921
4922 return false;
4923#else
4925 return false;
4926#endif
4927}
References ERROR, NO_XML_SUPPORT, and xml_ereport().
◆ XmlTableGetValue()
Definition at line 4938 of file xml.c.
4940{
4941#ifdef USE_LIBXML
4943 XmlTableBuilderData *xtCxt;
4944 volatile xmlXPathObjectPtr xpathobj = NULL;
4945
4946 xtCxt = GetXmlTableBuilderPrivateData(state, "XmlTableGetValue");
4947
4948 Assert(xtCxt->xpathobj &&
4949 xtCxt->xpathobj->type == XPATH_NODESET &&
4950 xtCxt->xpathobj->nodesetval != NULL);
4951
4952
4953 xmlSetStructuredErrorFunc(xtCxt->xmlerrcxt, xml_errorHandler);
4954
4955 *isnull = false;
4956
4957 Assert(xtCxt->xpathscomp[colnum] != NULL);
4958
4960 {
4961 xmlNodePtr cur;
4962 char *cstr = NULL;
4963
4964
4965 cur = xtCxt->xpathobj->nodesetval->nodeTab[xtCxt->row_count - 1];
4966 xtCxt->xpathcxt->node = cur;
4967
4968
4969 xpathobj = xmlXPathCompiledEval(xtCxt->xpathscomp[colnum], xtCxt->xpathcxt);
4970 if (xpathobj == NULL || xtCxt->xmlerrcxt->err_occurred)
4971 xml_ereport(xtCxt->xmlerrcxt, ERROR, ERRCODE_INVALID_ARGUMENT_FOR_XQUERY,
4972 "could not create XPath object");
4973
4974
4975
4976
4977
4978
4979
4980
4981 if (xpathobj->type == XPATH_NODESET)
4982 {
4983 int count = 0;
4984
4985 if (xpathobj->nodesetval != NULL)
4986 count = xpathobj->nodesetval->nodeNr;
4987
4988 if (xpathobj->nodesetval == NULL || count == 0)
4989 {
4990 *isnull = true;
4991 }
4992 else
4993 {
4994 if (typid == XMLOID)
4995 {
4996 text *textstr;
4998
4999
5001 for (int i = 0; i < count; i++)
5002 {
5003 textstr =
5004 xml_xmlnodetoxmltype(xpathobj->nodesetval->nodeTab[i],
5005 xtCxt->xmlerrcxt);
5006
5008 }
5009 cstr = str.data;
5010 }
5011 else
5012 {
5013 xmlChar *str;
5014
5015 if (count > 1)
5017 (errcode(ERRCODE_CARDINALITY_VIOLATION),
5018 errmsg("more than one value returned by column XPath expression")));
5019
5020 str = xmlXPathCastNodeSetToString(xpathobj->nodesetval);
5021 cstr = str ? xml_pstrdup_and_free(str) : "";
5022 }
5023 }
5024 }
5025 else if (xpathobj->type == XPATH_STRING)
5026 {
5027
5028 if (typid == XMLOID)
5029 cstr = escape_xml((char *) xpathobj->stringval);
5030 else
5031 cstr = (char *) xpathobj->stringval;
5032 }
5033 else if (xpathobj->type == XPATH_BOOLEAN)
5034 {
5035 char typcategory;
5036 bool typispreferred;
5037 xmlChar *str;
5038
5039
5041
5042 if (typcategory != TYPCATEGORY_NUMERIC)
5043 str = xmlXPathCastBooleanToString(xpathobj->boolval);
5044 else
5045 str = xmlXPathCastNumberToString(xmlXPathCastBooleanToNumber(xpathobj->boolval));
5046
5047 cstr = xml_pstrdup_and_free(str);
5048 }
5049 else if (xpathobj->type == XPATH_NUMBER)
5050 {
5051 xmlChar *str;
5052
5053 str = xmlXPathCastNumberToString(xpathobj->floatval);
5054 cstr = xml_pstrdup_and_free(str);
5055 }
5056 else
5057 elog(ERROR, "unexpected XPath object type %u", xpathobj->type);
5058
5059
5060
5061
5062
5063 Assert(cstr || *isnull);
5064
5065 if (!*isnull)
5067 cstr,
5068 state->typioparams[colnum],
5069 typmod);
5070 }
5072 {
5073 if (xpathobj != NULL)
5074 xmlXPathFreeObject(xpathobj);
5075 }
5077
5078 return result;
5079#else
5081 return 0;
5082#endif
5083}
Datum InputFunctionCall(FmgrInfo *flinfo, char *str, Oid typioparam, int32 typmod)
void get_type_category_preferred(Oid typid, char *typcategory, bool *typispreferred)
References appendStringInfoText(), Assert(), cur, elog, ereport, errcode(), errmsg(), ERROR, escape_xml(), get_type_category_preferred(), i, initStringInfo(), InputFunctionCall(), NO_XML_SUPPORT, PG_END_TRY, PG_FINALLY, PG_TRY, str, and xml_ereport().
◆ XmlTableInitOpaque()
Definition at line 4695 of file xml.c.
4696{
4697#ifdef USE_LIBXML
4698 volatile xmlParserCtxtPtr ctxt = NULL;
4699 XmlTableBuilderData *xtCxt;
4701
4702 xtCxt = palloc0(sizeof(XmlTableBuilderData));
4703 xtCxt->magic = XMLTABLE_CONTEXT_MAGIC;
4704 xtCxt->natts = natts;
4705 xtCxt->xpathscomp = palloc0(sizeof(xmlXPathCompExprPtr) * natts);
4706
4708
4710 {
4711 xmlInitParser();
4712
4713 ctxt = xmlNewParserCtxt();
4714 if (ctxt == NULL || xmlerrcxt->err_occurred)
4716 "could not allocate parser context");
4717 }
4719 {
4720 if (ctxt != NULL)
4721 xmlFreeParserCtxt(ctxt);
4722
4724
4726 }
4728
4729 xtCxt->xmlerrcxt = xmlerrcxt;
4730 xtCxt->ctxt = ctxt;
4731
4732 state->opaque = xtCxt;
4733#else
4735#endif
4736}
void * palloc0(Size size)
References ERROR, NO_XML_SUPPORT, palloc0(), PG_CATCH, PG_END_TRY, PG_RE_THROW, PG_TRY, pg_xml_done(), pg_xml_init(), PG_XML_STRICTNESS_ALL, and xml_ereport().
◆ XmlTableSetColumnFilter()
static void XmlTableSetColumnFilter ( struct TableFuncScanState * state, const char * path, int colnum ) | static |
---|
Definition at line 4858 of file xml.c.
4859{
4860#ifdef USE_LIBXML
4861 XmlTableBuilderData *xtCxt;
4862 xmlChar *xstr;
4863
4865
4866 xtCxt = GetXmlTableBuilderPrivateData(state, "XmlTableSetColumnFilter");
4867
4868 if (*path == '\0')
4870 (errcode(ERRCODE_INVALID_ARGUMENT_FOR_XQUERY),
4871 errmsg("column path filter must not be empty string")));
4872
4873 xstr = pg_xmlCharStrndup(path, strlen(path));
4874
4875
4876 Assert(xtCxt->xpathcxt != NULL);
4877
4878 xtCxt->xpathscomp[colnum] = xmlXPathCtxtCompile(xtCxt->xpathcxt, xstr);
4879 if (xtCxt->xpathscomp[colnum] == NULL || xtCxt->xmlerrcxt->err_occurred)
4880 xml_ereport(xtCxt->xmlerrcxt, ERROR, ERRCODE_INVALID_ARGUMENT_FOR_XQUERY,
4881 "invalid XPath expression");
4882#else
4884#endif
4885}
#define PointerIsValid(pointer)
References Assert(), ereport, errcode(), errmsg(), ERROR, NO_XML_SUPPORT, PointerIsValid, and xml_ereport().
◆ XmlTableSetDocument()
Definition at line 4743 of file xml.c.
4744{
4745#ifdef USE_LIBXML
4746 XmlTableBuilderData *xtCxt;
4748 char *str;
4749 xmlChar *xstr;
4750 int length;
4751 volatile xmlDocPtr doc = NULL;
4752 volatile xmlXPathContextPtr xpathcxt = NULL;
4753
4754 xtCxt = GetXmlTableBuilderPrivateData(state, "XmlTableSetDocument");
4755
4756
4757
4758
4759
4761
4762 length = strlen(str);
4763 xstr = pg_xmlCharStrndup(str, length);
4764
4766 {
4767 doc = xmlCtxtReadMemory(xtCxt->ctxt, (char *) xstr, length, NULL, NULL, 0);
4768 if (doc == NULL || xtCxt->xmlerrcxt->err_occurred)
4769 xml_ereport(xtCxt->xmlerrcxt, ERROR, ERRCODE_INVALID_XML_DOCUMENT,
4770 "could not parse XML document");
4771 xpathcxt = xmlXPathNewContext(doc);
4772 if (xpathcxt == NULL || xtCxt->xmlerrcxt->err_occurred)
4774 "could not allocate XPath context");
4775 xpathcxt->node = (xmlNodePtr) doc;
4776 }
4778 {
4779 if (xpathcxt != NULL)
4780 xmlXPathFreeContext(xpathcxt);
4781 if (doc != NULL)
4782 xmlFreeDoc(doc);
4783
4785 }
4787
4788 xtCxt->doc = doc;
4789 xtCxt->xpathcxt = xpathcxt;
4790#else
4792#endif
4793}
References DatumGetXmlP(), ERROR, NO_XML_SUPPORT, PG_CATCH, PG_END_TRY, PG_RE_THROW, PG_TRY, str, value, xml_ereport(), and xml_out_internal().
◆ XmlTableSetNamespace()
static void XmlTableSetNamespace ( struct TableFuncScanState * state, const char * name, const char * uri ) | static |
---|
Definition at line 4800 of file xml.c.
4801{
4802#ifdef USE_LIBXML
4803 XmlTableBuilderData *xtCxt;
4804
4805 if (name == NULL)
4807 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4808 errmsg("DEFAULT namespace is not supported")));
4809 xtCxt = GetXmlTableBuilderPrivateData(state, "XmlTableSetNamespace");
4810
4811 if (xmlXPathRegisterNs(xtCxt->xpathcxt,
4812 pg_xmlCharStrndup(name, strlen(name)),
4813 pg_xmlCharStrndup(uri, strlen(uri))))
4814 xml_ereport(xtCxt->xmlerrcxt, ERROR, ERRCODE_INVALID_ARGUMENT_FOR_XQUERY,
4815 "could not set XML namespace");
4816#else
4818#endif
4819}
References ereport, errcode(), errmsg(), ERROR, name, NO_XML_SUPPORT, and xml_ereport().
◆ XmlTableSetRowFilter()
static void XmlTableSetRowFilter ( struct TableFuncScanState * state, const char * path ) | static |
---|
Definition at line 4826 of file xml.c.
4827{
4828#ifdef USE_LIBXML
4829 XmlTableBuilderData *xtCxt;
4830 xmlChar *xstr;
4831
4832 xtCxt = GetXmlTableBuilderPrivateData(state, "XmlTableSetRowFilter");
4833
4834 if (*path == '\0')
4836 (errcode(ERRCODE_INVALID_ARGUMENT_FOR_XQUERY),
4837 errmsg("row path filter must not be empty string")));
4838
4839 xstr = pg_xmlCharStrndup(path, strlen(path));
4840
4841
4842 Assert(xtCxt->xpathcxt != NULL);
4843
4844 xtCxt->xpathcomp = xmlXPathCtxtCompile(xtCxt->xpathcxt, xstr);
4845 if (xtCxt->xpathcomp == NULL || xtCxt->xmlerrcxt->err_occurred)
4846 xml_ereport(xtCxt->xmlerrcxt, ERROR, ERRCODE_INVALID_ARGUMENT_FOR_XQUERY,
4847 "invalid XPath expression");
4848#else
4850#endif
4851}
References Assert(), ereport, errcode(), errmsg(), ERROR, NO_XML_SUPPORT, and xml_ereport().
◆ xmltext()
◆ xmltotext()
◆ xmltotext_with_options()
Definition at line 656 of file xml.c.
657{
658#ifdef USE_LIBXML
659 text *volatile result;
660 xmlDocPtr doc;
662 xmlNodePtr content_nodes;
663 volatile xmlBufferPtr buf = NULL;
664 volatile xmlSaveCtxtPtr ctxt = NULL;
667#endif
668
670 {
671
672
673
674
675
677 }
678
679#ifdef USE_LIBXML
680
681
682
683
684
685
686
688 &parsed_xmloptiontype, &content_nodes,
689 (Node *) &escontext);
691 {
692 if (doc)
693 xmlFreeDoc(doc);
694
696 (errcode(ERRCODE_NOT_AN_XML_DOCUMENT),
697 errmsg("not an XML document")));
698 }
699
700
701 if (!indent)
702 {
703 xmlFreeDoc(doc);
705 }
706
707
709
711 {
712 size_t decl_len = 0;
713
714
715 buf = xmlBufferCreate();
716
717 if (buf == NULL || xmlerrcxt->err_occurred)
719 "could not allocate xmlBuffer");
720
721
722 parse_xml_decl(xml_text2xmlChar(data), &decl_len, NULL, NULL, NULL);
723
724
725
726
727
728
729
730 if (decl_len == 0)
731 ctxt = xmlSaveToBuffer(buf, NULL,
732 XML_SAVE_NO_DECL | XML_SAVE_FORMAT);
733 else
734 ctxt = xmlSaveToBuffer(buf, NULL,
735 XML_SAVE_FORMAT);
736
737 if (ctxt == NULL || xmlerrcxt->err_occurred)
739 "could not allocate xmlSaveCtxt");
740
742 {
743
744 if (xmlSaveDoc(ctxt, doc) == -1 || xmlerrcxt->err_occurred)
746 "could not save document to xmlBuffer");
747 }
748 else if (content_nodes != NULL)
749 {
750
751
752
753
754
755
756 xmlNodePtr root;
757 xmlNodePtr oldroot;
759
760 root = xmlNewNode(NULL, (const xmlChar *) "content-root");
761 if (root == NULL || xmlerrcxt->err_occurred)
763 "could not allocate xml node");
764
765
766
767
768
769 oldroot = xmlDocSetRootElement(doc, root);
770 if (oldroot != NULL)
771 xmlFreeNode(oldroot);
772
773 xmlAddChildList(root, content_nodes);
774
775
776
777
778
779
780
781
782 newline = xmlNewDocText(NULL, (const xmlChar *) "\n");
783 if (newline == NULL || xmlerrcxt->err_occurred)
785 "could not allocate xml node");
786
787 for (xmlNodePtr node = root->children; node; node = node->next)
788 {
789
790 if (node->type != XML_TEXT_NODE && node->prev != NULL)
791 {
792 if (xmlSaveTree(ctxt, newline) == -1 || xmlerrcxt->err_occurred)
793 {
796 "could not save newline to xmlBuffer");
797 }
798 }
799
800 if (xmlSaveTree(ctxt, node) == -1 || xmlerrcxt->err_occurred)
801 {
804 "could not save content to xmlBuffer");
805 }
806 }
807
809 }
810
811 if (xmlSaveClose(ctxt) == -1 || xmlerrcxt->err_occurred)
812 {
813 ctxt = NULL;
815 "could not close xmlSaveCtxtPtr");
816 }
817
818
819
820
822 {
823 const char *str = (const char *) xmlBufferContent(buf);
824 int len = xmlBufferLength(buf);
825
826 while (len > 0 && (str[len - 1] == '\n' ||
829
831 }
832 else
833 result = (text *) xmlBuffer_to_xmltype(buf);
834 }
836 {
837 if (ctxt)
838 xmlSaveClose(ctxt);
840 xmlBufferFree(buf);
841 if (doc)
842 xmlFreeDoc(doc);
843
845
847 }
849
850 xmlBufferFree(buf);
851 xmlFreeDoc(doc);
852
854
855 return result;
856#else
858 return NULL;
859#endif
860}
References buf, cstring_to_text_with_len(), data, ereport, errcode(), errmsg(), ERROR, ErrorSaveContext::error_occurred, GetDatabaseEncoding(), len, newline, NO_XML_SUPPORT, PG_CATCH, PG_END_TRY, PG_RE_THROW, PG_TRY, pg_xml_done(), pg_xml_init(), PG_XML_STRICTNESS_ALL, root, str, xml_ereport(), and XMLOPTION_DOCUMENT.
Referenced by ExecEvalXmlExpr().
◆ xmlvalidate()
◆ xpath()
Definition at line 4532 of file xml.c.
4533{
4534#ifdef USE_LIBXML
4539
4541 xpath_internal(xpath_expr_text, data, namespaces,
4542 NULL, astate);
4544#else
4546 return 0;
4547#endif
4548}
#define PG_GETARG_ARRAYTYPE_P(n)
ArrayBuildState * initArrayResult(Oid element_type, MemoryContext rcontext, bool subcontext)
Datum makeArrayResult(ArrayBuildState *astate, MemoryContext rcontext)
#define PG_RETURN_DATUM(x)
MemoryContext CurrentMemoryContext
References CurrentMemoryContext, data, initArrayResult(), makeArrayResult(), NO_XML_SUPPORT, PG_GETARG_ARRAYTYPE_P, PG_GETARG_TEXT_PP, PG_GETARG_XML_P, and PG_RETURN_DATUM.
Referenced by pgxml_xpath(), xpath_bool(), xpath_list(), xpath_nodeset(), xpath_number(), and xpath_string().
◆ xpath_exists()
◆ xsd_schema_element_end()
static void xsd_schema_element_end ( StringInfo result) | static |
---|
◆ xsd_schema_element_start()
static void xsd_schema_element_start ( StringInfo result, const char * targetns ) | static |
---|
◆ xmlbinary
◆ xmloption
◆ XmlTableRoutine
Initial value:
=
{
}
static void XmlTableInitOpaque(struct TableFuncScanState *state, int natts)
static void XmlTableSetNamespace(struct TableFuncScanState *state, const char *name, const char *uri)
static void XmlTableSetRowFilter(struct TableFuncScanState *state, const char *path)
static Datum XmlTableGetValue(struct TableFuncScanState *state, int colnum, Oid typid, int32 typmod, bool *isnull)
static void XmlTableSetDocument(struct TableFuncScanState *state, Datum value)
static void XmlTableDestroyOpaque(struct TableFuncScanState *state)
static bool XmlTableFetchRow(struct TableFuncScanState *state)
static void XmlTableSetColumnFilter(struct TableFuncScanState *state, const char *path, int colnum)
Definition at line 223 of file xml.c.
Referenced by ExecInitTableFuncScan().