Add support for optionally escaping periods when converting SQL identifiers
authorPeter Eisentraut <peter_e@gmx.net>
Sun, 11 Feb 2007 22:18:16 +0000 (22:18 +0000)
committerPeter Eisentraut <peter_e@gmx.net>
Sun, 11 Feb 2007 22:18:16 +0000 (22:18 +0000)
to XML names, which will be required for supporting XML export.

src/backend/parser/parse_expr.c
src/backend/utils/adt/xml.c
src/include/utils/xml.h

index 61b8c0d53d3a08984ab5b7fc6ff70768b9077a16..410999f2c450da67eb5809eee5d848e689e598ab 100644 (file)
@@ -1389,7 +1389,7 @@ transformXmlExpr(ParseState *pstate, XmlExpr *x)
 
        newx->op = x->op;
        if (x->name)
-               newx->name = map_sql_identifier_to_xml_name(x->name, false);
+               newx->name = map_sql_identifier_to_xml_name(x->name, false, false);
        else
                newx->name = NULL;
 
@@ -1411,10 +1411,10 @@ transformXmlExpr(ParseState *pstate, XmlExpr *x)
                expr = transformExpr(pstate, r->val);
 
                if (r->name)
-                       argname = map_sql_identifier_to_xml_name(r->name, false);
+                       argname = map_sql_identifier_to_xml_name(r->name, false, false);
                else if (IsA(r->val, ColumnRef))
                        argname = map_sql_identifier_to_xml_name(FigureColname(r->val),
-                                                                                                        true);
+                                                                                                        true, false);
                else
                {
                        ereport(ERROR,
index 5648c7de08b9f31c8d94e596dedf5da204f78e86..768392c8497367a2ff198a8fd2585a1a83e56820 100644 (file)
@@ -1318,8 +1318,14 @@ is_valid_xml_namechar(pg_wchar c)
  * Map SQL identifier to XML name; see SQL/XML:2003 section 9.1.
  */
 char *
-map_sql_identifier_to_xml_name(char *ident, bool fully_escaped)
+map_sql_identifier_to_xml_name(char *ident, bool fully_escaped, bool escape_period)
 {
+       /*
+        * SQL/XML doesn't make use of this case anywhere, so it's
+        * probably a mistake.
+        */
+       Assert(fully_escaped || !escape_period);
+
 #ifdef USE_LIBXML
        StringInfoData buf;
        char *p;
@@ -1340,6 +1346,8 @@ map_sql_identifier_to_xml_name(char *ident, bool fully_escaped)
                        else
                                appendStringInfo(&buf, "_x0058_");
                }
+               else if (escape_period && *p == '.')
+                       appendStringInfo(&buf, "_x002E_");
                else
                {
                        pg_wchar u = sqlchar_to_unicode(p);
index 6b6aedf54038f5a895ce0ca55056ef46e429b715..e673c48b687bc7647cc877aeb9ba12cc90de3a8d 100644 (file)
@@ -53,7 +53,7 @@ extern xmltype *xmlroot(xmltype *data, text *version, int standalone);
 extern bool xml_is_document(xmltype *arg);
 extern text *xmltotext_with_xmloption(xmltype *data, XmlOptionType xmloption_arg);
 
-extern char *map_sql_identifier_to_xml_name(char *ident, bool fully_escaped);
+extern char *map_sql_identifier_to_xml_name(char *ident, bool fully_escaped, bool escape_period);
 extern char *map_xml_name_to_sql_identifier(char *name);
 extern char *map_sql_value_to_xml_value(Datum value, Oid type);