Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8832f0f

Browse files
committed
De-escape XML names when reverse-compiling XML expressions.
1 parent9aefd56 commit8832f0f

File tree

3 files changed

+76
-11
lines changed

3 files changed

+76
-11
lines changed

‎src/backend/utils/adt/ruleutils.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* ruleutils.c- Functions to convert stored expressions/querytrees
33
*back to source text
44
*
5-
* $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.238 2006/12/24 00:29:19 tgl Exp $
5+
* $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.239 2006/12/29 10:50:22 petere Exp $
66
**********************************************************************/
77

88
#include"postgres.h"
@@ -3810,11 +3810,8 @@ get_rule_expr(Node *node, deparse_context *context,
38103810
}
38113811
if (xexpr->name)
38123812
{
3813-
/*
3814-
* XXX need to de-escape the name
3815-
*/
38163813
appendStringInfo(buf,"NAME %s",
3817-
quote_identifier(xexpr->name));
3814+
quote_identifier(map_xml_name_to_sql_identifier(xexpr->name)));
38183815
needcomma= true;
38193816
}
38203817
if (xexpr->named_args)
@@ -3834,11 +3831,8 @@ get_rule_expr(Node *node, deparse_context *context,
38343831
if (needcomma)
38353832
appendStringInfoString(buf,", ");
38363833
get_rule_expr((Node*)e,context, true);
3837-
/*
3838-
* XXX need to de-escape the name
3839-
*/
38403834
appendStringInfo(buf," AS %s",
3841-
quote_identifier(argname));
3835+
quote_identifier(map_xml_name_to_sql_identifier(argname)));
38423836
needcomma= true;
38433837
}
38443838
if (xexpr->op!=IS_XMLFOREST)

‎src/backend/utils/adt/xml.c

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.7 2006/12/28 14:28:36 petere Exp $
10+
* $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.8 2006/12/29 10:50:22 petere Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -882,6 +882,42 @@ sqlchar_to_unicode(char *s)
882882
}
883883

884884

885+
staticchar*
886+
unicode_to_sqlchar(pg_wcharc)
887+
{
888+
charutf8string[4]= {'\0','\0','\0','\0' };
889+
890+
if (c <=0x7F)
891+
{
892+
utf8string[0]=c;
893+
}
894+
elseif (c <=0x7FF)
895+
{
896+
utf8string[0]=0xC0 | ((c >>6)&0x1F);
897+
utf8string[1]=0x80 | (c&0x3F);
898+
}
899+
elseif (c <=0xFFFF)
900+
{
901+
utf8string[0]=0xE0 | ((c >>12)&0x0F);
902+
utf8string[1]=0x80 | ((c >>6)&0x3F);
903+
utf8string[2]=0x80 | (c&0x3F);
904+
}
905+
else
906+
{
907+
utf8string[0]=0xF0 | ((c >>18)&0x07);
908+
utf8string[1]=0x80 | ((c >>12)&0x3F);
909+
utf8string[2]=0x80 | ((c >>6)&0x3F);
910+
utf8string[3]=0x80 | (c&0x3F);
911+
912+
}
913+
914+
return (char*)pg_do_encoding_conversion((unsignedchar*)utf8string,
915+
pg_mblen(utf8string),
916+
PG_UTF8,
917+
GetDatabaseEncoding());
918+
}
919+
920+
885921
staticbool
886922
is_valid_xml_namefirst(pg_wcharc)
887923
{
@@ -949,3 +985,37 @@ map_sql_identifier_to_xml_name(char *ident, bool fully_escaped)
949985
returnNULL;
950986
#endif/* not USE_LIBXML */
951987
}
988+
989+
990+
/*
991+
* The inverse; see SQL/XML:2003 section 9.17.
992+
*/
993+
char*
994+
map_xml_name_to_sql_identifier(char*name)
995+
{
996+
StringInfoDatabuf;
997+
char*p;
998+
999+
initStringInfo(&buf);
1000+
1001+
for (p=name;*p;p+=pg_mblen(p))
1002+
{
1003+
if (*p=='_'&&*(p+1)=='x'
1004+
&&isxdigit((unsignedchar)*(p+2))
1005+
&&isxdigit((unsignedchar)*(p+3))
1006+
&&isxdigit((unsignedchar)*(p+4))
1007+
&&isxdigit((unsignedchar)*(p+5))
1008+
&&*(p+6)=='_')
1009+
{
1010+
unsignedintu;
1011+
1012+
sscanf(p+2,"%X",&u);
1013+
appendStringInfoString(&buf,unicode_to_sqlchar(u));
1014+
p+=6;
1015+
}
1016+
else
1017+
appendBinaryStringInfo(&buf,p,pg_mblen(p));
1018+
}
1019+
1020+
returnbuf.data;
1021+
}

‎src/include/utils/xml.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/utils/xml.h,v 1.4 2006/12/28 14:28:36 petere Exp $
10+
* $PostgreSQL: pgsql/src/include/utils/xml.h,v 1.5 2006/12/29 10:50:22 petere Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -37,5 +37,6 @@ extern xmltype *xmlpi(char *target, text *arg);
3737
externxmltype*xmlroot(xmltype*data,text*version,intstandalone);
3838

3939
externchar*map_sql_identifier_to_xml_name(char*ident,boolfully_escaped);
40+
externchar*map_xml_name_to_sql_identifier(char*name);
4041

4142
#endif/* XML_H */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp