]> granicus.if.org Git - postgresql/blobdiff - src/backend/utils/adt/xml.c
Update copyright for 2014
[postgresql] / src / backend / utils / adt / xml.c
index 051d4036816f6c68573f0d29e785c7cb72f84577..d36751855b63089bd45b687f62374711057f46cf 100644 (file)
@@ -4,7 +4,7 @@
  *       XML data type support.
  *
  *
- * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1996-2014, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * src/backend/utils/adt/xml.c
@@ -442,9 +442,9 @@ xmlcomment(PG_FUNCTION_ARGS)
                                 errmsg("invalid XML comment")));
 
        initStringInfo(&buf);
-       appendStringInfo(&buf, "<!--");
+       appendStringInfoString(&buf, "<!--");
        appendStringInfoText(&buf, arg);
-       appendStringInfo(&buf, "-->");
+       appendStringInfoString(&buf, "-->");
 
        PG_RETURN_XML_P(stringinfo_to_xmltype(&buf));
 #else
@@ -1499,7 +1499,7 @@ xml_pstrdup(const char *string)
 /*
  * xmlPgEntityLoader --- entity loader callback function
  *
- * Silently prevent any external entity URL from being loaded.  We don't want
+ * Silently prevent any external entity URL from being loaded. We don't want
  * to throw an error, so instead make the entity appear to expand to an empty
  * string.
  *
@@ -1609,6 +1609,7 @@ xml_errorHandler(void *data, xmlErrorPtr error)
                case XML_FROM_NONE:
                case XML_FROM_MEMORY:
                case XML_FROM_IO:
+
                        /*
                         * Suppress warnings about undeclared entities.  We need to do
                         * this to avoid problems due to not loading DTD definitions.
@@ -1851,19 +1852,19 @@ map_sql_identifier_to_xml_name(char *ident, bool fully_escaped,
        for (p = ident; *p; p += pg_mblen(p))
        {
                if (*p == ':' && (p == ident || fully_escaped))
-                       appendStringInfo(&buf, "_x003A_");
+                       appendStringInfoString(&buf, "_x003A_");
                else if (*p == '_' && *(p + 1) == 'x')
-                       appendStringInfo(&buf, "_x005F_");
+                       appendStringInfoString(&buf, "_x005F_");
                else if (fully_escaped && p == ident &&
                                 pg_strncasecmp(p, "xml", 3) == 0)
                {
                        if (*p == 'x')
-                               appendStringInfo(&buf, "_x0078_");
+                               appendStringInfoString(&buf, "_x0078_");
                        else
-                               appendStringInfo(&buf, "_x0058_");
+                               appendStringInfoString(&buf, "_x0058_");
                }
                else if (escape_period && *p == '.')
-                       appendStringInfo(&buf, "_x002E_");
+                       appendStringInfoString(&buf, "_x002E_");
                else
                {
                        pg_wchar        u = sqlchar_to_unicode(p);
@@ -2001,6 +2002,12 @@ map_sql_value_to_xml_value(Datum value, Oid type, bool xml_escape_strings)
                bool            isvarlena;
                char       *str;
 
+               /*
+                * Flatten domains; the special-case treatments below should apply to,
+                * eg, domains over boolean not just boolean.
+                */
+               type = getBaseType(type);
+
                /*
                 * Special XSD formatting for some data types
                 */
@@ -2285,7 +2292,7 @@ schema_get_xml_visible_tables(Oid nspid)
        StringInfoData query;
 
        initStringInfo(&query);
-       appendStringInfo(&query, "SELECT oid FROM pg_catalog.pg_class WHERE relnamespace = %u AND relkind IN ('r', 'v') AND pg_catalog.has_table_privilege (oid, 'SELECT') ORDER BY relname;", nspid);
+       appendStringInfo(&query, "SELECT oid FROM pg_catalog.pg_class WHERE relnamespace = %u AND relkind IN ('r', 'm', 'v') AND pg_catalog.has_table_privilege (oid, 'SELECT') ORDER BY relname;", nspid);
 
        return query_to_oid_list(query.data);
 }
@@ -2311,7 +2318,7 @@ static List *
 database_get_xml_visible_tables(void)
 {
        /* At the moment there is no order required here. */
-       return query_to_oid_list("SELECT oid FROM pg_catalog.pg_class WHERE relkind IN ('r', 'v') AND pg_catalog.has_table_privilege (pg_class.oid, 'SELECT') AND relnamespace IN (" XML_VISIBLE_SCHEMAS ");");
+       return query_to_oid_list("SELECT oid FROM pg_catalog.pg_class WHERE relkind IN ('r', 'm', 'v') AND pg_catalog.has_table_privilege (pg_class.oid, 'SELECT') AND relnamespace IN (" XML_VISIBLE_SCHEMAS ");");
 }
 
 
@@ -2431,9 +2438,9 @@ xmldata_root_element_start(StringInfo result, const char *eltname,
                if (strlen(targetns) > 0)
                        appendStringInfo(result, " xsi:schemaLocation=\"%s #\"", targetns);
                else
-                       appendStringInfo(result, " xsi:noNamespaceSchemaLocation=\"#\"");
+                       appendStringInfoString(result, " xsi:noNamespaceSchemaLocation=\"#\"");
        }
-       appendStringInfo(result, ">\n");
+       appendStringInfoString(result, ">\n");
 }
 
 
@@ -2678,7 +2685,7 @@ schema_to_xml(PG_FUNCTION_ARGS)
        Oid                     nspid;
 
        schemaname = NameStr(*name);
-       nspid = LookupExplicitNamespace(schemaname);
+       nspid = LookupExplicitNamespace(schemaname, false);
 
        PG_RETURN_XML_P(stringinfo_to_xmltype(schema_to_xml_internal(nspid, NULL,
                                                                           nulls, tableforest, targetns, true)));
@@ -2724,7 +2731,7 @@ schema_to_xmlschema_internal(const char *schemaname, bool nulls,
 
        result = makeStringInfo();
 
-       nspid = LookupExplicitNamespace(schemaname);
+       nspid = LookupExplicitNamespace(schemaname, false);
 
        xsd_schema_element_start(result, targetns);
 
@@ -2782,7 +2789,7 @@ schema_to_xml_and_xmlschema(PG_FUNCTION_ARGS)
        StringInfo      xmlschema;
 
        schemaname = NameStr(*name);
-       nspid = LookupExplicitNamespace(schemaname);
+       nspid = LookupExplicitNamespace(schemaname, false);
 
        xmlschema = schema_to_xmlschema_internal(schemaname, nulls,
                                                                                         tableforest, targetns);
@@ -2938,7 +2945,7 @@ map_multipart_sql_identifier_to_xml_name(char *a, char *b, char *c, char *d)
        initStringInfo(&result);
 
        if (a)
-               appendStringInfo(&result, "%s",
+               appendStringInfoString(&result,
                                                 map_sql_identifier_to_xml_name(a, true, true));
        if (b)
                appendStringInfo(&result, ".%s",
@@ -3205,71 +3212,71 @@ map_sql_type_to_xml_name(Oid typeoid, int typmod)
        {
                case BPCHAROID:
                        if (typmod == -1)
-                               appendStringInfo(&result, "CHAR");
+                               appendStringInfoString(&result, "CHAR");
                        else
                                appendStringInfo(&result, "CHAR_%d", typmod - VARHDRSZ);
                        break;
                case VARCHAROID:
                        if (typmod == -1)
-                               appendStringInfo(&result, "VARCHAR");
+                               appendStringInfoString(&result, "VARCHAR");
                        else
                                appendStringInfo(&result, "VARCHAR_%d", typmod - VARHDRSZ);
                        break;
                case NUMERICOID:
                        if (typmod == -1)
-                               appendStringInfo(&result, "NUMERIC");
+                               appendStringInfoString(&result, "NUMERIC");
                        else
                                appendStringInfo(&result, "NUMERIC_%d_%d",
                                                                 ((typmod - VARHDRSZ) >> 16) & 0xffff,
                                                                 (typmod - VARHDRSZ) & 0xffff);
                        break;
                case INT4OID:
-                       appendStringInfo(&result, "INTEGER");
+                       appendStringInfoString(&result, "INTEGER");
                        break;
                case INT2OID:
-                       appendStringInfo(&result, "SMALLINT");
+                       appendStringInfoString(&result, "SMALLINT");
                        break;
                case INT8OID:
-                       appendStringInfo(&result, "BIGINT");
+                       appendStringInfoString(&result, "BIGINT");
                        break;
                case FLOAT4OID:
-                       appendStringInfo(&result, "REAL");
+                       appendStringInfoString(&result, "REAL");
                        break;
                case FLOAT8OID:
-                       appendStringInfo(&result, "DOUBLE");
+                       appendStringInfoString(&result, "DOUBLE");
                        break;
                case BOOLOID:
-                       appendStringInfo(&result, "BOOLEAN");
+                       appendStringInfoString(&result, "BOOLEAN");
                        break;
                case TIMEOID:
                        if (typmod == -1)
-                               appendStringInfo(&result, "TIME");
+                               appendStringInfoString(&result, "TIME");
                        else
                                appendStringInfo(&result, "TIME_%d", typmod);
                        break;
                case TIMETZOID:
                        if (typmod == -1)
-                               appendStringInfo(&result, "TIME_WTZ");
+                               appendStringInfoString(&result, "TIME_WTZ");
                        else
                                appendStringInfo(&result, "TIME_WTZ_%d", typmod);
                        break;
                case TIMESTAMPOID:
                        if (typmod == -1)
-                               appendStringInfo(&result, "TIMESTAMP");
+                               appendStringInfoString(&result, "TIMESTAMP");
                        else
                                appendStringInfo(&result, "TIMESTAMP_%d", typmod);
                        break;
                case TIMESTAMPTZOID:
                        if (typmod == -1)
-                               appendStringInfo(&result, "TIMESTAMP_WTZ");
+                               appendStringInfoString(&result, "TIMESTAMP_WTZ");
                        else
                                appendStringInfo(&result, "TIMESTAMP_WTZ_%d", typmod);
                        break;
                case DATEOID:
-                       appendStringInfo(&result, "DATE");
+                       appendStringInfoString(&result, "DATE");
                        break;
                case XMLOID:
-                       appendStringInfo(&result, "XML");
+                       appendStringInfoString(&result, "XML");
                        break;
                default:
                        {
@@ -3363,7 +3370,7 @@ map_sql_type_to_xmlschema_type(Oid typeoid, int typmod)
 
        if (typeoid == XMLOID)
        {
-               appendStringInfo(&result,
+               appendStringInfoString(&result,
                                                 "<xsd:complexType mixed=\"true\">\n"
                                                 "  <xsd:sequence>\n"
                                                 "    <xsd:any name=\"element\" minOccurs=\"0\" maxOccurs=\"unbounded\" processContents=\"skip\"/>\n"
@@ -3386,8 +3393,7 @@ map_sql_type_to_xmlschema_type(Oid typeoid, int typmod)
                                        appendStringInfo(&result,
                                                                         "    <xsd:maxLength value=\"%d\"/>\n",
                                                                         typmod - VARHDRSZ);
-                               appendStringInfo(&result,
-                                                                "  </xsd:restriction>\n");
+                               appendStringInfoString(&result, "  </xsd:restriction>\n");
                                break;
 
                        case BYTEAOID:
@@ -3437,17 +3443,17 @@ map_sql_type_to_xmlschema_type(Oid typeoid, int typmod)
                                break;
 
                        case FLOAT4OID:
-                               appendStringInfo(&result,
+                               appendStringInfoString(&result,
                                "  <xsd:restriction base=\"xsd:float\"></xsd:restriction>\n");
                                break;
 
                        case FLOAT8OID:
-                               appendStringInfo(&result,
+                               appendStringInfoString(&result,
                                                                 "  <xsd:restriction base=\"xsd:double\"></xsd:restriction>\n");
                                break;
 
                        case BOOLOID:
-                               appendStringInfo(&result,
+                               appendStringInfoString(&result,
                                                                 "  <xsd:restriction base=\"xsd:boolean\"></xsd:restriction>\n");
                                break;
 
@@ -3498,7 +3504,7 @@ map_sql_type_to_xmlschema_type(Oid typeoid, int typmod)
                                }
 
                        case DATEOID:
-                               appendStringInfo(&result,
+                               appendStringInfoString(&result,
                                                                 "  <xsd:restriction base=\"xsd:date\">\n"
                                                                 "    <xsd:pattern value=\"\\p{Nd}{4}-\\p{Nd}{2}-\\p{Nd}{2}\"/>\n"
                                                                 "  </xsd:restriction>\n");
@@ -3518,8 +3524,7 @@ map_sql_type_to_xmlschema_type(Oid typeoid, int typmod)
                                }
                                break;
                }
-               appendStringInfo(&result,
-                                                "</xsd:simpleType>\n");
+               appendStringInfoString(&result, "</xsd:simpleType>\n");
        }
 
        return result.data;