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 2836 of file xml.c.
◆ XML_VISIBLE_SCHEMAS_EXCLUDE
#define XML_VISIBLE_SCHEMAS_EXCLUDE "(nspname ~ '^pg_' OR nspname = 'information_schema')"
Definition at line 2834 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 2911 of file xml.c.
2912{
2918
2922
2924
2925 if (!tableforest)
2926 {
2929 }
2930
2933 if (portal == NULL)
2935 (errcode(ERRCODE_UNDEFINED_CURSOR),
2936 errmsg("cursor \"%s\" does not exist", name)));
2937
2941 tableforest, targetns, true);
2942
2944
2945 if (!tableforest)
2947
2949}
#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 3092 of file xml.c.
3093{
3098 const char *xmlschema;
3100
3103 if (portal == NULL)
3105 (errcode(ERRCODE_UNDEFINED_CURSOR),
3106 errmsg("cursor \"%s\" does not exist", name)));
3107 if (portal->tupDesc == NULL)
3109 (errcode(ERRCODE_INVALID_CURSOR_STATE),
3110 errmsg("portal \"%s\" does not return tuples", name)));
3111
3114 tableforest, targetns));
3116
3118}
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 3464 of file xml.c.
3465{
3470
3472
3474 nulls, tableforest, targetns)));
3475}
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 3354 of file xml.c.
3356{
3358 List *nspid_list;
3360 char *xmlcn;
3361
3363 true, false);
3365
3368
3369 if (xmlschema)
3371
3373
3375
3376 foreach(cell, nspid_list)
3377 {
3380
3382 tableforest, targetns, false);
3383
3386 }
3387
3389
3391
3392 return result;
3393}
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 3409 of file xml.c.
3411{
3412 List *relid_list;
3413 List *nspid_list;
3414 List *tupdesc_list;
3417
3419
3421
3423
3426
3427 tupdesc_list = NIL;
3428 foreach(cell, relid_list)
3429 {
3431
3435 }
3436
3439
3442
3444
3446
3447 return result;
3448}
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 3692 of file xml.c.
3694{
3696 char *xmlcn;
3697 char *catalogtypename;
3700
3702
3704
3706
3709 NULL,
3710 NULL);
3711
3713 "<xsd:complexType name=\"%s\">\n", catalogtypename);
3715 " xsd:all\n");
3716
3717 foreach(cell, nspid_list)
3718 {
3724 nspname,
3725 NULL);
3726
3728 " <xsd:element name=\"%s\" type=\"%s\"/>\n",
3729 xmlsn, schematypename);
3730 }
3731
3733 " \n");
3735 "\n\n");
3736
3738 "<xsd:element name=\"%s\" type=\"%s\"/>\n\n",
3739 xmlcn, catalogtypename);
3740
3741 return result.data;
3742}
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 2378 of file xml.c.
2380{
2381#ifdef USE_LIBXML
2383 const char *p;
2384
2385
2386
2387
2388
2389 Assert(fully_escaped || !escape_period);
2390
2392
2394 {
2395 if (*p == ':' && (p == ident || fully_escaped))
2397 else if (*p == '_' && *(p + 1) == 'x')
2399 else if (fully_escaped && p == ident &&
2401 {
2402 if (*p == 'x')
2404 else
2406 }
2407 else if (escape_period && *p == '.')
2409 else
2410 {
2411 pg_wchar u = sqlchar_to_unicode(p);
2412
2413 if ((p == ident)
2414 ? !is_valid_xml_namefirst(u)
2415 : !is_valid_xml_namechar(u))
2417 else
2419 }
2420 }
2421
2422 return buf.data;
2423#else
2425 return NULL;
2426#endif
2427}
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 3619 of file xml.c.
3621{
3623 char *nspname;
3624 char *xmlsn;
3625 char *schematypename;
3628
3631
3633
3635
3638 nspname,
3639 NULL);
3640
3642 "<xsd:complexType name=\"%s\">\n", schematypename);
3643 if (!tableforest)
3645 " xsd:all\n");
3646 else
3648 " xsd:sequence\n");
3649
3650 foreach(cell, relid_list)
3651 {
3657 nspname,
3659
3660 if (!tableforest)
3662 " <xsd:element name=\"%s\" type=\"%s\"/>\n",
3663 xmltn, tabletypename);
3664 else
3666 " <xsd:element name=\"%s\" type=\"%s\" minOccurs=\"0\" maxOccurs=\"unbounded\"/>\n",
3667 xmltn, tabletypename);
3668 }
3669
3670 if (!tableforest)
3672 " \n");
3673 else
3675 " \n");
3677 "\n\n");
3678
3680 "<xsd:element name=\"%s\" type=\"%s\"/>\n\n",
3681 xmlsn, schematypename);
3682
3683 return result.data;
3684}
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 3514 of file xml.c.
3516{
3517 int i;
3518 char *xmltn;
3519 char *tabletypename;
3520 char *rowtypename;
3522
3524
3526 {
3529
3532 elog(ERROR, "cache lookup failed for relation %u", relid);
3534
3536 true, false);
3537
3541 NameStr(reltuple->relname));
3542
3546 NameStr(reltuple->relname));
3547
3549 }
3550 else
3551 {
3552 if (tableforest)
3553 xmltn = "row";
3554 else
3555 xmltn = "table";
3556
3557 tabletypename = "TableType";
3558 rowtypename = "RowType";
3559 }
3560
3562
3565
3567 "<xsd:complexType name=\"%s\">\n"
3568 " xsd:sequence\n",
3569 rowtypename);
3570
3571 for (i = 0; i < tupdesc->natts; i++)
3572 {
3574
3575 if (att->attisdropped)
3576 continue;
3578 " <xsd:element name=\"%s\" type=\"%s\"%s>\n",
3580 true, false),
3582 nulls ? " nillable=\"true\"" : " minOccurs=\"0\"");
3583 }
3584
3586 " \n"
3587 "\n\n");
3588
3589 if (!tableforest)
3590 {
3592 "<xsd:complexType name=\"%s\">\n"
3593 " xsd:sequence\n"
3594 " <xsd:element name=\"row\" type=\"%s\" minOccurs=\"0\" maxOccurs=\"unbounded\"/>\n"
3595 " \n"
3596 "\n\n",
3597 tabletypename, rowtypename);
3598
3600 "<xsd:element name=\"%s\" type=\"%s\"/>\n\n",
3601 xmltn, tabletypename);
3602 }
3603 else
3605 "<xsd:element name=\"%s\" type=\"%s\"/>\n\n",
3606 xmltn, rowtypename);
3607
3609
3610 return result.data;
3611}
#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 3749 of file xml.c.
3750{
3752
3754
3755 switch (typeoid)
3756 {
3757 case BPCHAROID:
3758 if (typmod == -1)
3760 else
3762 break;
3763 case VARCHAROID:
3764 if (typmod == -1)
3766 else
3768 break;
3769 case NUMERICOID:
3770 if (typmod == -1)
3772 else
3774 ((typmod - VARHDRSZ) >> 16) & 0xffff,
3775 (typmod - VARHDRSZ) & 0xffff);
3776 break;
3777 case INT4OID:
3779 break;
3780 case INT2OID:
3782 break;
3783 case INT8OID:
3785 break;
3786 case FLOAT4OID:
3788 break;
3789 case FLOAT8OID:
3791 break;
3792 case BOOLOID:
3794 break;
3795 case TIMEOID:
3796 if (typmod == -1)
3798 else
3800 break;
3801 case TIMETZOID:
3802 if (typmod == -1)
3804 else
3806 break;
3807 case TIMESTAMPOID:
3808 if (typmod == -1)
3810 else
3812 break;
3813 case TIMESTAMPTZOID:
3814 if (typmod == -1)
3816 else
3818 break;
3819 case DATEOID:
3821 break;
3822 case XMLOID:
3824 break;
3825 default:
3826 {
3829
3832 elog(ERROR, "cache lookup failed for type %u", typeoid);
3834
3839 NameStr(typtuple->typname)));
3840
3842 }
3843 }
3844
3845 return result.data;
3846}
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 3909 of file xml.c.
3910{
3913
3915
3916 if (typeoid == XMLOID)
3917 {
3919 "<xsd:complexType mixed=\"true\">\n"
3920 " xsd:sequence\n"
3921 " <xsd:any name=\"element\" minOccurs=\"0\" maxOccurs=\"unbounded\" processContents=\"skip\"/>\n"
3922 " \n"
3923 "\n");
3924 }
3925 else
3926 {
3928 "<xsd:simpleType name=\"%s\">\n", typename);
3929
3930 switch (typeoid)
3931 {
3932 case BPCHAROID:
3933 case VARCHAROID:
3934 case TEXTOID:
3936 " <xsd:restriction base=\"xsd:string\">\n");
3937 if (typmod != -1)
3939 " <xsd:maxLength value=\"%d\"/>\n",
3942 break;
3943
3944 case BYTEAOID:
3946 " <xsd:restriction base=\"xsd:%s\">\n"
3947 " \n",
3949 break;
3950
3951 case NUMERICOID:
3952 if (typmod != -1)
3954 " <xsd:restriction base=\"xsd:decimal\">\n"
3955 " <xsd:totalDigits value=\"%d\"/>\n"
3956 " <xsd:fractionDigits value=\"%d\"/>\n"
3957 " \n",
3958 ((typmod - VARHDRSZ) >> 16) & 0xffff,
3959 (typmod - VARHDRSZ) & 0xffff);
3960 break;
3961
3962 case INT2OID:
3964 " <xsd:restriction base=\"xsd:short\">\n"
3965 " <xsd:maxInclusive value=\"%d\"/>\n"
3966 " <xsd:minInclusive value=\"%d\"/>\n"
3967 " \n",
3968 SHRT_MAX, SHRT_MIN);
3969 break;
3970
3971 case INT4OID:
3973 " <xsd:restriction base=\"xsd:int\">\n"
3974 " <xsd:maxInclusive value=\"%d\"/>\n"
3975 " <xsd:minInclusive value=\"%d\"/>\n"
3976 " \n",
3977 INT_MAX, INT_MIN);
3978 break;
3979
3980 case INT8OID:
3982 " <xsd:restriction base=\"xsd:long\">\n"
3983 " <xsd:maxInclusive value=\"" INT64_FORMAT "\"/>\n"
3984 " <xsd:minInclusive value=\"" INT64_FORMAT "\"/>\n"
3985 " \n",
3988 break;
3989
3990 case FLOAT4OID:
3992 " <xsd:restriction base=\"xsd:float\">\n");
3993 break;
3994
3995 case FLOAT8OID:
3997 " <xsd:restriction base=\"xsd:double\">\n");
3998 break;
3999
4000 case BOOLOID:
4002 " <xsd:restriction base=\"xsd:boolean\">\n");
4003 break;
4004
4005 case TIMEOID:
4006 case TIMETZOID:
4007 {
4008 const char *tz = (typeoid == TIMETZOID ? "(\\+|-)\\p{Nd}{2}:\\p{Nd}{2}" : "");
4009
4010 if (typmod == -1)
4012 " <xsd:restriction base=\"xsd:time\">\n"
4013 " <xsd:pattern value=\"\\p{Nd}{2}:\\p{Nd}{2}:\\p{Nd}{2}(.\\p{Nd}+)?%s\"/>\n"
4014 " \n", tz);
4015 else if (typmod == 0)
4017 " <xsd:restriction base=\"xsd:time\">\n"
4018 " <xsd:pattern value=\"\\p{Nd}{2}:\\p{Nd}{2}:\\p{Nd}{2}%s\"/>\n"
4019 " \n", tz);
4020 else
4022 " <xsd:restriction base=\"xsd:time\">\n"
4023 " <xsd:pattern value=\"\\p{Nd}{2}:\\p{Nd}{2}:\\p{Nd}{2}.\\p{Nd}{%d}%s\"/>\n"
4024 " \n", typmod - VARHDRSZ, tz);
4025 break;
4026 }
4027
4028 case TIMESTAMPOID:
4029 case TIMESTAMPTZOID:
4030 {
4031 const char *tz = (typeoid == TIMESTAMPTZOID ? "(\\+|-)\\p{Nd}{2}:\\p{Nd}{2}" : "");
4032
4033 if (typmod == -1)
4035 " <xsd:restriction base=\"xsd:dateTime\">\n"
4036 " <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"
4037 " \n", tz);
4038 else if (typmod == 0)
4040 " <xsd:restriction base=\"xsd:dateTime\">\n"
4041 " <xsd:pattern value=\"\\p{Nd}{4}-\\p{Nd}{2}-\\p{Nd}{2}T\\p{Nd}{2}:\\p{Nd}{2}:\\p{Nd}{2}%s\"/>\n"
4042 " \n", tz);
4043 else
4045 " <xsd:restriction base=\"xsd:dateTime\">\n"
4046 " <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"
4047 " \n", typmod - VARHDRSZ, tz);
4048 break;
4049 }
4050
4051 case DATEOID:
4053 " <xsd:restriction base=\"xsd:date\">\n"
4054 " <xsd:pattern value=\"\\p{Nd}{4}-\\p{Nd}{2}-\\p{Nd}{2}\"/>\n"
4055 " \n");
4056 break;
4057
4058 default:
4059 if (get_typtype(typeoid) == TYPTYPE_DOMAIN)
4060 {
4061 Oid base_typeoid;
4062 int32 base_typmod = -1;
4063
4065
4067 " <xsd:restriction base=\"%s\"/>\n",
4069 }
4070 break;
4071 }
4073 }
4074
4075 return result.data;
4076}
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 3854 of file xml.c.
3855{
3857 int i;
3860
3861
3862 foreach(cell0, tupdesc_list)
3863 {
3865
3866 for (i = 0; i < tupdesc->natts; i++)
3867 {
3869
3870 if (att->attisdropped)
3871 continue;
3873 }
3874 }
3875
3876
3877 foreach(cell0, uniquetypes)
3878 {
3881
3882 if (basetypid != typid)
3884 }
3885
3886
3888
3889 foreach(cell0, uniquetypes)
3890 {
3893 -1));
3894 }
3895
3896 return result.data;
3897}
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 2476 of file xml.c.
2477{
2479 {
2481 Oid elmtype;
2483 bool elmbyval;
2484 char elmalign;
2485 int num_elems;
2486 Datum *elem_values;
2487 bool *elem_nulls;
2489 int i;
2490
2494
2496 elmlen, elmbyval, elmalign,
2497 &elem_values, &elem_nulls,
2498 &num_elems);
2499
2501
2502 for (i = 0; i < num_elems; i++)
2503 {
2504 if (elem_nulls[i])
2505 continue;
2509 elmtype, true));
2511 }
2512
2513 pfree(elem_values);
2514 pfree(elem_nulls);
2515
2516 return buf.data;
2517 }
2518 else
2519 {
2520 Oid typeOut;
2521 bool isvarlena;
2522 char *str;
2523
2524
2525
2526
2527
2529
2530
2531
2532
2533 switch (type)
2534 {
2535 case BOOLOID:
2537 return "true";
2538 else
2539 return "false";
2540
2541 case DATEOID:
2542 {
2546
2548
2551 (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
2552 errmsg("date out of range"),
2553 errdetail("XML does not support infinite date values.")));
2557
2559 }
2560
2561 case TIMESTAMPOID:
2562 {
2567
2569
2570
2573 (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
2574 errmsg("timestamp out of range"),
2575 errdetail("XML does not support infinite timestamp values.")));
2578 else
2580 (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
2581 errmsg("timestamp out of range")));
2582
2584 }
2585
2586 case TIMESTAMPTZOID:
2587 {
2590 int tz;
2592 const char *tzn = NULL;
2594
2596
2597
2600 (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
2601 errmsg("timestamp out of range"),
2602 errdetail("XML does not support infinite timestamp values.")));
2605 else
2607 (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
2608 errmsg("timestamp out of range")));
2609
2611 }
2612
2613#ifdef USE_LIBXML
2614 case BYTEAOID:
2615 {
2618 volatile xmlBufferPtr buf = NULL;
2619 volatile xmlTextWriterPtr writer = NULL;
2620 char *result;
2621
2623
2625 {
2626 buf = xmlBufferCreate();
2627 if (buf == NULL || xmlerrcxt->err_occurred)
2629 "could not allocate xmlBuffer");
2630 writer = xmlNewTextWriterMemory(buf, 0);
2631 if (writer == NULL || xmlerrcxt->err_occurred)
2633 "could not allocate xmlTextWriter");
2634
2636 xmlTextWriterWriteBase64(writer, VARDATA_ANY(bstr),
2638 else
2639 xmlTextWriterWriteBinHex(writer, VARDATA_ANY(bstr),
2641
2642
2643 xmlFreeTextWriter(writer);
2644 writer = NULL;
2645
2646 result = pstrdup((const char *) xmlBufferContent(buf));
2647 }
2649 {
2650 if (writer)
2651 xmlFreeTextWriter(writer);
2652 if (buf)
2653 xmlBufferFree(buf);
2654
2656
2658 }
2660
2661 xmlBufferFree(buf);
2662
2664
2665 return result;
2666 }
2667#endif
2668
2669 }
2670
2671
2672
2673
2676
2677
2678 if (type == XMLOID || !xml_escape_strings)
2679 return str;
2680
2681
2683 }
2684}
#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 2434 of file xml.c.
2435{
2437 const char *p;
2438
2440
2442 {
2443 if (*p == '_' && *(p + 1) == 'x'
2444 && isxdigit((unsigned char) *(p + 2))
2445 && isxdigit((unsigned char) *(p + 3))
2446 && isxdigit((unsigned char) *(p + 4))
2447 && isxdigit((unsigned char) *(p + 5))
2448 && *(p + 6) == '_')
2449 {
2451 unsigned int u;
2452
2453 sscanf(p + 2, "%X", &u);
2456 p += 6;
2457 }
2458 else
2460 }
2461
2462 return buf.data;
2463}
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 2784 of file xml.c.
2785{
2788 int spi_result;
2789
2790 spi_result = SPI_execute(query, true, 0);
2792 elog(ERROR, "SPI_execute returned %s for %s",
2794
2796 {
2798 bool isnull;
2799
2802 1,
2803 &isnull);
2804 if (!isnull)
2806 }
2807
2808 return list;
2809}
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 2897 of file xml.c.
2898{
2903
2905 NULL, nulls, tableforest,
2906 targetns, true)));
2907}
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 3143 of file xml.c.
3144{
3149
3150 const char *xmlschema;
3153
3155
3157 elog(ERROR, "SPI_prepare(\"%s\") failed", query);
3158
3160 elog(ERROR, "SPI_cursor_open(\"%s\") failed", query);
3161
3163 InvalidOid, nulls, tableforest, targetns));
3166
3168 xmlschema, nulls, tableforest,
3169 targetns, true)));
3170}
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 2999 of file xml.c.
3002{
3004 char *xmltn;
3006
3007 if (tablename)
3009 else
3010 xmltn = "table";
3011
3013
3017 (errcode(ERRCODE_DATA_EXCEPTION),
3018 errmsg("invalid query")));
3019
3020 if (!tableforest)
3021 {
3023 targetns, top_level);
3025 }
3026
3027 if (xmlschema)
3029
3032 tableforest, targetns, top_level);
3033
3034 if (!tableforest)
3036
3038
3039 return result;
3040}
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 3063 of file xml.c.
3064{
3069 const char *result;
3072
3074
3076 elog(ERROR, "SPI_prepare(\"%s\") failed", query);
3077
3079 elog(ERROR, "SPI_cursor_open(\"%s\") failed", query);
3080
3083 tableforest, targetns));
3086
3088}
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 3222 of file xml.c.
3223{
3228
3229 char *schemaname;
3231
3234
3236 nulls, tableforest, targetns, true)));
3237}
#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 3326 of file xml.c.
3327{
3332 char *schemaname;
3335
3338
3340 tableforest, targetns);
3341
3343 xmlschema->data, nulls,
3344 tableforest, targetns, true)));
3345}
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 3179 of file xml.c.
3181{
3183 char *xmlsn;
3184 List *relid_list;
3186
3188 true, false);
3190
3193
3194 if (xmlschema)
3196
3198
3200
3201 foreach(cell, relid_list)
3202 {
3205
3207 targetns, false);
3208
3211 }
3212
3214
3216
3217 return result;
3218}
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 3313 of file xml.c.
3314{
3319
3321 nulls, tableforest, targetns)));
3322}
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 3268 of file xml.c.
3270{
3272 List *relid_list;
3273 List *tupdesc_list;
3276
3278
3280
3282
3284
3286
3287 tupdesc_list = NIL;
3288 foreach(cell, relid_list)
3289 {
3291
3295 }
3296
3299
3302 nulls, tableforest, targetns));
3303
3305
3307
3308 return result;
3309}
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 4084 of file xml.c.
4087{
4088 int i;
4089 char *xmltn;
4090
4091 if (tablename)
4093 else
4094 {
4095 if (tableforest)
4096 xmltn = "row";
4097 else
4098 xmltn = "table";
4099 }
4100
4101 if (tableforest)
4103 else
4105
4107 {
4108 char *colname;
4110 bool isnull;
4111
4113 true, false);
4116 i,
4117 &isnull);
4118 if (isnull)
4119 {
4120 if (nulls)
4121 appendStringInfo(result, " <%s xsi:nil=\"true\"/>\n", colname);
4122 }
4123 else
4125 colname,
4128 colname);
4129 }
4130
4131 if (tableforest)
4132 {
4135 }
4136 else
4138}
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 3122 of file xml.c.
3123{
3129 const char *xmlschema;
3130
3133 tableforest, targetns);
3135
3137 xmlschema, nulls, tableforest,
3138 targetns, true)));
3139}
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 2866 of file xml.c.
2869{
2871
2877 xmlschema, nulls, tableforest,
2878 targetns, top_level);
2879}
#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 3044 of file xml.c.
3045{
3050 const char *result;
3052
3055 tableforest, targetns);
3057
3059}
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 857 of file xml.c.
860{
861#ifdef USE_LIBXML
863 List *named_arg_strings;
864 List *arg_strings;
865 int i;
869 volatile xmlBufferPtr buf = NULL;
870 volatile xmlTextWriterPtr writer = NULL;
871
872
873
874
875
876
877
878
879 named_arg_strings = NIL;
880 i = 0;
882 {
884 char *str;
885
886 if (named_argnull[i])
887 str = NULL;
888 else
891 false);
892 named_arg_strings = lappend(named_arg_strings, str);
893 i++;
894 }
895
896 arg_strings = NIL;
897 i = 0;
899 {
901 char *str;
902
903
904 if (!argnull[i])
905 {
908 true);
909 arg_strings = lappend(arg_strings, str);
910 }
911 i++;
912 }
913
915
917 {
918 buf = xmlBufferCreate();
919 if (buf == NULL || xmlerrcxt->err_occurred)
921 "could not allocate xmlBuffer");
922 writer = xmlNewTextWriterMemory(buf, 0);
923 if (writer == NULL || xmlerrcxt->err_occurred)
925 "could not allocate xmlTextWriter");
926
927 xmlTextWriterStartElement(writer, (xmlChar *) xexpr->name);
928
929 forboth(arg, named_arg_strings, narg, xexpr->arg_names)
930 {
933
935 xmlTextWriterWriteAttribute(writer,
936 (xmlChar *) argname,
937 (xmlChar *) str);
938 }
939
940 foreach(arg, arg_strings)
941 {
943
944 xmlTextWriterWriteRaw(writer, (xmlChar *) str);
945 }
946
947 xmlTextWriterEndElement(writer);
948
949
950 xmlFreeTextWriter(writer);
951 writer = NULL;
952
953 result = xmlBuffer_to_xmltype(buf);
954 }
956 {
957 if (writer)
958 xmlFreeTextWriter(writer);
960 xmlBufferFree(buf);
961
963
965 }
967
968 xmlBufferFree(buf);
969
971
972 return result;
973#else
975 return NULL;
976#endif
977}
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 999 of file xml.c.
1000{
1001#ifdef USE_LIBXML
1004
1007 (errcode(ERRCODE_INVALID_XML_PROCESSING_INSTRUCTION),
1008 errmsg("invalid XML processing instruction"),
1009 errdetail("XML processing instruction target name cannot be \"%s\".", target)));
1010
1011
1012
1013
1014
1015 *result_is_null = arg_is_null;
1016 if (*result_is_null)
1017 return NULL;
1018
1020
1022
1023 if (arg != NULL)
1024 {
1026
1028 if (strstr(string, "?>") != NULL)
1030 (errcode(ERRCODE_INVALID_XML_PROCESSING_INSTRUCTION),
1031 errmsg("invalid XML processing instruction"),
1032 errdetail("XML processing instruction cannot contain \"?>\".")));
1033
1037 }
1039
1042 return result;
1043#else
1045 return NULL;
1046#endif
1047}
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 1051 of file xml.c.
1052{
1053#ifdef USE_LIBXML
1054 char *str;
1055 size_t len;
1056 xmlChar *orig_version;
1057 int orig_standalone;
1059
1062
1063 parse_xml_decl((xmlChar *) str, &len, &orig_version, NULL, &orig_standalone);
1064
1065 if (version)
1066 orig_version = xml_text2xmlChar(version);
1067 else
1068 orig_version = NULL;
1069
1070 switch (standalone)
1071 {
1073 orig_standalone = 1;
1074 break;
1076 orig_standalone = 0;
1077 break;
1079 orig_standalone = -1;
1080 break;
1082
1083 break;
1084 }
1085
1087 print_xml_decl(&buf, orig_version, 0, orig_standalone);
1089
1091#else
1093 return NULL;
1094#endif
1095}
@ 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 5077 of file xml.c.
5078{
5079#ifdef USE_LIBXML
5080 XmlTableBuilderData *xtCxt;
5081
5082 xtCxt = GetXmlTableBuilderPrivateData(state, "XmlTableDestroyOpaque");
5083
5084
5085 xmlSetStructuredErrorFunc(xtCxt->xmlerrcxt, xml_errorHandler);
5086
5087 if (xtCxt->xpathscomp != NULL)
5088 {
5089 int i;
5090
5091 for (i = 0; i < xtCxt->natts; i++)
5092 if (xtCxt->xpathscomp[i] != NULL)
5093 xmlXPathFreeCompExpr(xtCxt->xpathscomp[i]);
5094 }
5095
5096 if (xtCxt->xpathobj != NULL)
5097 xmlXPathFreeObject(xtCxt->xpathobj);
5098 if (xtCxt->xpathcomp != NULL)
5099 xmlXPathFreeCompExpr(xtCxt->xpathcomp);
5100 if (xtCxt->xpathcxt != NULL)
5101 xmlXPathFreeContext(xtCxt->xpathcxt);
5102 if (xtCxt->doc != NULL)
5103 xmlFreeDoc(xtCxt->doc);
5104 if (xtCxt->ctxt != NULL)
5105 xmlFreeParserCtxt(xtCxt->ctxt);
5106
5108
5109
5110 xtCxt->magic = 0;
5111 state->opaque = NULL;
5112
5113#else
5115#endif
5116}
References i, NO_XML_SUPPORT, and pg_xml_done().
◆ XmlTableFetchRow()
Definition at line 4880 of file xml.c.
4881{
4882#ifdef USE_LIBXML
4883 XmlTableBuilderData *xtCxt;
4884
4885 xtCxt = GetXmlTableBuilderPrivateData(state, "XmlTableFetchRow");
4886
4887
4888 xmlSetStructuredErrorFunc(xtCxt->xmlerrcxt, xml_errorHandler);
4889
4890 if (xtCxt->xpathobj == NULL)
4891 {
4892 xtCxt->xpathobj = xmlXPathCompiledEval(xtCxt->xpathcomp, xtCxt->xpathcxt);
4893 if (xtCxt->xpathobj == NULL || xtCxt->xmlerrcxt->err_occurred)
4894 xml_ereport(xtCxt->xmlerrcxt, ERROR, ERRCODE_INVALID_ARGUMENT_FOR_XQUERY,
4895 "could not create XPath object");
4896
4897 xtCxt->row_count = 0;
4898 }
4899
4900 if (xtCxt->xpathobj->type == XPATH_NODESET)
4901 {
4902 if (xtCxt->xpathobj->nodesetval != NULL)
4903 {
4904 if (xtCxt->row_count++ < xtCxt->xpathobj->nodesetval->nodeNr)
4905 return true;
4906 }
4907 }
4908
4909 return false;
4910#else
4912 return false;
4913#endif
4914}
References ERROR, NO_XML_SUPPORT, and xml_ereport().
◆ XmlTableGetValue()
Definition at line 4925 of file xml.c.
4927{
4928#ifdef USE_LIBXML
4930 XmlTableBuilderData *xtCxt;
4931 volatile xmlXPathObjectPtr xpathobj = NULL;
4932
4933 xtCxt = GetXmlTableBuilderPrivateData(state, "XmlTableGetValue");
4934
4935 Assert(xtCxt->xpathobj &&
4936 xtCxt->xpathobj->type == XPATH_NODESET &&
4937 xtCxt->xpathobj->nodesetval != NULL);
4938
4939
4940 xmlSetStructuredErrorFunc(xtCxt->xmlerrcxt, xml_errorHandler);
4941
4942 *isnull = false;
4943
4944 Assert(xtCxt->xpathscomp[colnum] != NULL);
4945
4947 {
4948 xmlNodePtr cur;
4949 char *cstr = NULL;
4950
4951
4952 cur = xtCxt->xpathobj->nodesetval->nodeTab[xtCxt->row_count - 1];
4953 xtCxt->xpathcxt->node = cur;
4954
4955
4956 xpathobj = xmlXPathCompiledEval(xtCxt->xpathscomp[colnum], xtCxt->xpathcxt);
4957 if (xpathobj == NULL || xtCxt->xmlerrcxt->err_occurred)
4958 xml_ereport(xtCxt->xmlerrcxt, ERROR, ERRCODE_INVALID_ARGUMENT_FOR_XQUERY,
4959 "could not create XPath object");
4960
4961
4962
4963
4964
4965
4966
4967
4968 if (xpathobj->type == XPATH_NODESET)
4969 {
4970 int count = 0;
4971
4972 if (xpathobj->nodesetval != NULL)
4973 count = xpathobj->nodesetval->nodeNr;
4974
4975 if (xpathobj->nodesetval == NULL || count == 0)
4976 {
4977 *isnull = true;
4978 }
4979 else
4980 {
4981 if (typid == XMLOID)
4982 {
4983 text *textstr;
4985
4986
4988 for (int i = 0; i < count; i++)
4989 {
4990 textstr =
4991 xml_xmlnodetoxmltype(xpathobj->nodesetval->nodeTab[i],
4992 xtCxt->xmlerrcxt);
4993
4995 }
4996 cstr = str.data;
4997 }
4998 else
4999 {
5000 xmlChar *str;
5001
5002 if (count > 1)
5004 (errcode(ERRCODE_CARDINALITY_VIOLATION),
5005 errmsg("more than one value returned by column XPath expression")));
5006
5007 str = xmlXPathCastNodeSetToString(xpathobj->nodesetval);
5008 cstr = str ? xml_pstrdup_and_free(str) : "";
5009 }
5010 }
5011 }
5012 else if (xpathobj->type == XPATH_STRING)
5013 {
5014
5015 if (typid == XMLOID)
5016 cstr = escape_xml((char *) xpathobj->stringval);
5017 else
5018 cstr = (char *) xpathobj->stringval;
5019 }
5020 else if (xpathobj->type == XPATH_BOOLEAN)
5021 {
5022 char typcategory;
5023 bool typispreferred;
5024 xmlChar *str;
5025
5026
5028
5029 if (typcategory != TYPCATEGORY_NUMERIC)
5030 str = xmlXPathCastBooleanToString(xpathobj->boolval);
5031 else
5032 str = xmlXPathCastNumberToString(xmlXPathCastBooleanToNumber(xpathobj->boolval));
5033
5034 cstr = xml_pstrdup_and_free(str);
5035 }
5036 else if (xpathobj->type == XPATH_NUMBER)
5037 {
5038 xmlChar *str;
5039
5040 str = xmlXPathCastNumberToString(xpathobj->floatval);
5041 cstr = xml_pstrdup_and_free(str);
5042 }
5043 else
5044 elog(ERROR, "unexpected XPath object type %u", xpathobj->type);
5045
5046
5047
5048
5049
5050 Assert(cstr || *isnull);
5051
5052 if (!*isnull)
5054 cstr,
5055 state->typioparams[colnum],
5056 typmod);
5057 }
5059 {
5060 if (xpathobj != NULL)
5061 xmlXPathFreeObject(xpathobj);
5062 }
5064
5065 return result;
5066#else
5068 return 0;
5069#endif
5070}
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 4682 of file xml.c.
4683{
4684#ifdef USE_LIBXML
4685 volatile xmlParserCtxtPtr ctxt = NULL;
4686 XmlTableBuilderData *xtCxt;
4688
4689 xtCxt = palloc0(sizeof(XmlTableBuilderData));
4690 xtCxt->magic = XMLTABLE_CONTEXT_MAGIC;
4691 xtCxt->natts = natts;
4692 xtCxt->xpathscomp = palloc0(sizeof(xmlXPathCompExprPtr) * natts);
4693
4695
4697 {
4698 xmlInitParser();
4699
4700 ctxt = xmlNewParserCtxt();
4701 if (ctxt == NULL || xmlerrcxt->err_occurred)
4703 "could not allocate parser context");
4704 }
4706 {
4707 if (ctxt != NULL)
4708 xmlFreeParserCtxt(ctxt);
4709
4711
4713 }
4715
4716 xtCxt->xmlerrcxt = xmlerrcxt;
4717 xtCxt->ctxt = ctxt;
4718
4719 state->opaque = xtCxt;
4720#else
4722#endif
4723}
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 4845 of file xml.c.
4846{
4847#ifdef USE_LIBXML
4848 XmlTableBuilderData *xtCxt;
4849 xmlChar *xstr;
4850
4852
4853 xtCxt = GetXmlTableBuilderPrivateData(state, "XmlTableSetColumnFilter");
4854
4855 if (*path == '\0')
4857 (errcode(ERRCODE_INVALID_ARGUMENT_FOR_XQUERY),
4858 errmsg("column path filter must not be empty string")));
4859
4860 xstr = pg_xmlCharStrndup(path, strlen(path));
4861
4862
4863 Assert(xtCxt->xpathcxt != NULL);
4864
4865 xtCxt->xpathscomp[colnum] = xmlXPathCtxtCompile(xtCxt->xpathcxt, xstr);
4866 if (xtCxt->xpathscomp[colnum] == NULL || xtCxt->xmlerrcxt->err_occurred)
4867 xml_ereport(xtCxt->xmlerrcxt, ERROR, ERRCODE_INVALID_ARGUMENT_FOR_XQUERY,
4868 "invalid XPath expression");
4869#else
4871#endif
4872}
#define PointerIsValid(pointer)
References Assert(), ereport, errcode(), errmsg(), ERROR, NO_XML_SUPPORT, PointerIsValid, and xml_ereport().
◆ XmlTableSetDocument()
Definition at line 4730 of file xml.c.
4731{
4732#ifdef USE_LIBXML
4733 XmlTableBuilderData *xtCxt;
4735 char *str;
4736 xmlChar *xstr;
4737 int length;
4738 volatile xmlDocPtr doc = NULL;
4739 volatile xmlXPathContextPtr xpathcxt = NULL;
4740
4741 xtCxt = GetXmlTableBuilderPrivateData(state, "XmlTableSetDocument");
4742
4743
4744
4745
4746
4748
4749 length = strlen(str);
4750 xstr = pg_xmlCharStrndup(str, length);
4751
4753 {
4754 doc = xmlCtxtReadMemory(xtCxt->ctxt, (char *) xstr, length, NULL, NULL, 0);
4755 if (doc == NULL || xtCxt->xmlerrcxt->err_occurred)
4756 xml_ereport(xtCxt->xmlerrcxt, ERROR, ERRCODE_INVALID_XML_DOCUMENT,
4757 "could not parse XML document");
4758 xpathcxt = xmlXPathNewContext(doc);
4759 if (xpathcxt == NULL || xtCxt->xmlerrcxt->err_occurred)
4761 "could not allocate XPath context");
4762 xpathcxt->node = (xmlNodePtr) doc;
4763 }
4765 {
4766 if (xpathcxt != NULL)
4767 xmlXPathFreeContext(xpathcxt);
4768 if (doc != NULL)
4769 xmlFreeDoc(doc);
4770
4772 }
4774
4775 xtCxt->doc = doc;
4776 xtCxt->xpathcxt = xpathcxt;
4777#else
4779#endif
4780}
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 4787 of file xml.c.
4788{
4789#ifdef USE_LIBXML
4790 XmlTableBuilderData *xtCxt;
4791
4792 if (name == NULL)
4794 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4795 errmsg("DEFAULT namespace is not supported")));
4796 xtCxt = GetXmlTableBuilderPrivateData(state, "XmlTableSetNamespace");
4797
4798 if (xmlXPathRegisterNs(xtCxt->xpathcxt,
4799 pg_xmlCharStrndup(name, strlen(name)),
4800 pg_xmlCharStrndup(uri, strlen(uri))))
4801 xml_ereport(xtCxt->xmlerrcxt, ERROR, ERRCODE_INVALID_ARGUMENT_FOR_XQUERY,
4802 "could not set XML namespace");
4803#else
4805#endif
4806}
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 4813 of file xml.c.
4814{
4815#ifdef USE_LIBXML
4816 XmlTableBuilderData *xtCxt;
4817 xmlChar *xstr;
4818
4819 xtCxt = GetXmlTableBuilderPrivateData(state, "XmlTableSetRowFilter");
4820
4821 if (*path == '\0')
4823 (errcode(ERRCODE_INVALID_ARGUMENT_FOR_XQUERY),
4824 errmsg("row path filter must not be empty string")));
4825
4826 xstr = pg_xmlCharStrndup(path, strlen(path));
4827
4828
4829 Assert(xtCxt->xpathcxt != NULL);
4830
4831 xtCxt->xpathcomp = xmlXPathCtxtCompile(xtCxt->xpathcxt, xstr);
4832 if (xtCxt->xpathcomp == NULL || xtCxt->xmlerrcxt->err_occurred)
4833 xml_ereport(xtCxt->xmlerrcxt, ERROR, ERRCODE_INVALID_ARGUMENT_FOR_XQUERY,
4834 "invalid XPath expression");
4835#else
4837#endif
4838}
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;
758
759 root = xmlNewNode(NULL, (const xmlChar *) "content-root");
760 if (root == NULL || xmlerrcxt->err_occurred)
762 "could not allocate xml node");
763
764
765 xmlDocSetRootElement(doc, root);
766 xmlAddChildList(root, content_nodes);
767
768
769
770
771
772
773
774
775 newline = xmlNewDocText(NULL, (const xmlChar *) "\n");
776 if (newline == NULL || xmlerrcxt->err_occurred)
778 "could not allocate xml node");
779
780 for (xmlNodePtr node = root->children; node; node = node->next)
781 {
782
783 if (node->type != XML_TEXT_NODE && node->prev != NULL)
784 {
785 if (xmlSaveTree(ctxt, newline) == -1 || xmlerrcxt->err_occurred)
786 {
789 "could not save newline to xmlBuffer");
790 }
791 }
792
793 if (xmlSaveTree(ctxt, node) == -1 || xmlerrcxt->err_occurred)
794 {
797 "could not save content to xmlBuffer");
798 }
799 }
800
802 }
803
804 if (xmlSaveClose(ctxt) == -1 || xmlerrcxt->err_occurred)
805 {
806 ctxt = NULL;
808 "could not close xmlSaveCtxtPtr");
809 }
810
811
812
813
815 {
816 const char *str = (const char *) xmlBufferContent(buf);
817 int len = xmlBufferLength(buf);
818
819 while (len > 0 && (str[len - 1] == '\n' ||
822
824 }
825 else
826 result = (text *) xmlBuffer_to_xmltype(buf);
827 }
829 {
830 if (ctxt)
831 xmlSaveClose(ctxt);
833 xmlBufferFree(buf);
834 if (doc)
835 xmlFreeDoc(doc);
836
838
840 }
842
843 xmlBufferFree(buf);
844 xmlFreeDoc(doc);
845
847
848 return result;
849#else
851 return NULL;
852#endif
853}
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 4519 of file xml.c.
4520{
4521#ifdef USE_LIBXML
4526
4528 xpath_internal(xpath_expr_text, data, namespaces,
4529 NULL, astate);
4531#else
4533 return 0;
4534#endif
4535}
#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().