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

Commit22bd156

Browse files
committed
Various fixes in the logic of XML functions:
- Add new SQL command SET XML OPTION (also available via regular GUC) to control the DOCUMENT vs. CONTENT option in implicit parsing and serialization operations.- Subtle corrections in the handling of the standalone property in xmlroot().- Allow xmlroot() to work on content fragments.- Subtle corrections in the handling of the version property in xmlconcat().- Code refactoring for producing XML declarations.
1 parent9597446 commit22bd156

File tree

13 files changed

+329
-121
lines changed

13 files changed

+329
-121
lines changed

‎doc/src/sgml/config.sgml

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.105 2007/01/2504:35:10 momjian Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.106 2007/01/2511:53:50 petere Exp $ -->
22

33
<chapter Id="runtime-config">
44
<title>Server Configuration</title>
@@ -3558,6 +3558,38 @@ SELECT * FROM parent WHERE key = 2400;
35583558
</listitem>
35593559
</varlistentry>
35603560

3561+
<varlistentry id="guc-xmloption" xreflabel="xmloption">
3562+
<term><varname>xmloption</varname> (<type>string</type>)</term>
3563+
<indexterm>
3564+
<primary><varname>xmloption</> configuration parameter</primary>
3565+
</indexterm>
3566+
<indexterm>
3567+
<primary><varname>SET XML OPTION</></primary>
3568+
</indexterm>
3569+
<indexterm>
3570+
<primary><varname>XML option</></primary>
3571+
</indexterm>
3572+
<listitem>
3573+
<para>
3574+
Sets whether <literal>DOCUMENT</literal> or
3575+
<literal>CONTENT</literal> is implicit when converting between
3576+
XML and character string values. See <xref
3577+
linkend="datatype-xml"> for a description of this. Valid
3578+
values are <literal>DOCUMENT</literal> and
3579+
<literal>CONTENT</literal>. The default is
3580+
<literal>CONTENT</literal>.
3581+
</para>
3582+
3583+
<para>
3584+
According to the SQL standard, the command to set this option is
3585+
<synopsis>
3586+
SET XML OPTION { DOCUMENT | CONTENT };
3587+
</synopsis>
3588+
This syntax is also available in PostgreSQL.
3589+
</para>
3590+
</listitem>
3591+
</varlistentry>
3592+
35613593
</variablelist>
35623594
</sect2>
35633595
<sect2 id="runtime-config-client-format">

‎doc/src/sgml/datatype.sgml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/datatype.sgml,v 1.185 2007/01/18 13:59:11 petere Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/datatype.sgml,v 1.186 2007/01/25 11:53:50 petere Exp $ -->
22

33
<chapter id="datatype">
44
<title id="datatype-title">Data Types</title>
@@ -3474,6 +3474,24 @@ XMLSERIALIZE ( { DOCUMENT | CONTENT } <replaceable>value</replaceable> AS <repla
34743474
you to simply cast the value.
34753475
</para>
34763476

3477+
<para>
3478+
When character string values are cast to or from type
3479+
<type>xml</type> without going through <type>XMLPARSE</type> or
3480+
<type>XMLSERIALIZE</type>, respectively, the choice of
3481+
<literal>DOCUMENT</literal> versus <literal>CONTENT</literal> is
3482+
determined by the <quote>XML option</quote> session configuration
3483+
parameter, which can be set using the standard command
3484+
<synopsis>
3485+
SET XML OPTION { DOCUMENT | CONTENT };
3486+
</synopsis>
3487+
or the more PostgreSQL-like syntax
3488+
<synopsis>
3489+
SET xmloption TO { DOCUMENT | CONTENT };
3490+
</synopsis>
3491+
The default is <literal>CONTENT</literal>, so all forms of XML
3492+
data are allowed.
3493+
</para>
3494+
34773495
<para>
34783496
Care must be taken when dealing with multiple character encodings
34793497
on the client, server, and in the XML data passed through them.

‎src/backend/executor/execQual.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/executor/execQual.c,v 1.208 2007/01/20 09:27:19 petere Exp $
11+
* $PostgreSQL: pgsql/src/backend/executor/execQual.c,v 1.209 2007/01/25 11:53:50 petere Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -2797,10 +2797,7 @@ ExecEvalXml(XmlExprState *xmlExpr, ExprContext *econtext,
27972797

27982798
e= (ExprState*)lthird(xmlExpr->args);
27992799
value=ExecEvalExpr(e,econtext,&isnull,NULL);
2800-
if (isnull)
2801-
standalone=0;
2802-
else
2803-
standalone= (DatumGetBool(value) ?1 :-1);
2800+
standalone=DatumGetInt32(value);
28042801

28052802
*isNull= false;
28062803

‎src/backend/parser/gram.y

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.576 2007/01/23 05:07:17 tgl Exp $
14+
* $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.577 2007/01/25 11:53:51 petere Exp $
1515
*
1616
* HISTORY
1717
* AUTHORDATEMAJOR EVENT
@@ -60,6 +60,7 @@
6060
#include"utils/date.h"
6161
#include"utils/datetime.h"
6262
#include"utils/numeric.h"
63+
#include"utils/xml.h"
6364

6465

6566
/* Location tracking support --- simpler than bison's default*/
@@ -439,7 +440,7 @@ static Node *makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args)
439440

440441
WHEN WHERE WHITESPACE_P WITH WITHOUT WORK WRITE
441442

442-
XMLATTRIBUTES XMLCONCAT XMLELEMENT XMLFOREST XMLPARSE
443+
XML_PXMLATTRIBUTES XMLCONCAT XMLELEMENT XMLFOREST XMLPARSE
443444
XMLPI XMLROOT XMLSERIALIZE
444445

445446
YEAR_P YES_P
@@ -1112,6 +1113,13 @@ set_rest: var_name TO var_list_or_default
11121113
n->args = NIL;
11131114
$$ = n;
11141115
}
1116+
|XML_POPTIONdocument_or_content
1117+
{
1118+
VariableSetStmt *n = makeNode(VariableSetStmt);
1119+
n->name ="xmloption";
1120+
n->args = list_make1(makeStringConst($3 ?"DOCUMENT" :"CONTENT",NULL));
1121+
$$ = n;
1122+
}
11151123
;
11161124

11171125
var_name:
@@ -7938,21 +7946,13 @@ xml_root_version: VERSION_P a_expr
79387946
;
79397947

79407948
opt_xml_root_standalone:',' STANDALONE_P YES_P
7941-
{ $$ = (Node *)makeBoolAConst(true); }
7949+
{ $$ = (Node *)makeIntConst(XML_STANDALONE_YES); }
79427950
|',' STANDALONE_P NO
7943-
{ $$ = (Node *)makeBoolAConst(false); }
7951+
{ $$ = (Node *)makeIntConst(XML_STANDALONE_NO); }
79447952
|',' STANDALONE_P NO VALUE_P
7945-
{
7946-
A_Const *val =makeNode(A_Const);
7947-
val->val.type = T_Null;
7948-
$$ = (Node *) val;
7949-
}
7953+
{ $$ = (Node *)makeIntConst(XML_STANDALONE_NO_VALUE); }
79507954
|/*EMPTY*/
7951-
{
7952-
A_Const *val =makeNode(A_Const);
7953-
val->val.type = T_Null;
7954-
$$ = (Node *) val;
7955-
}
7955+
{ $$ = (Node *)makeIntConst(XML_STANDALONE_OMITTED); }
79567956
;
79577957

79587958
xml_attributes: XMLATTRIBUTES'(' xml_attribute_list')'{ $$ = $3; }
@@ -8864,6 +8864,7 @@ unreserved_keyword:
88648864
| WITHOUT
88658865
| WORK
88668866
| WRITE
8867+
| XML_P
88678868
| YEAR_P
88688869
| YES_P
88698870
| ZONE

‎src/backend/parser/keywords.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/parser/keywords.c,v 1.183 2007/01/23 05:07:18 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/parser/keywords.c,v 1.184 2007/01/25 11:53:51 petere Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -380,6 +380,7 @@ static const ScanKeyword ScanKeywords[] = {
380380
{"without",WITHOUT},
381381
{"work",WORK},
382382
{"write",WRITE},
383+
{"xml",XML_P},
383384
{"xmlattributes",XMLATTRIBUTES},
384385
{"xmlconcat",XMLCONCAT},
385386
{"xmlelement",XMLELEMENT},

‎src/backend/parser/parse_expr.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/parser/parse_expr.c,v 1.208 2007/01/14 13:11:53 petere Exp $
11+
* $PostgreSQL: pgsql/src/backend/parser/parse_expr.c,v 1.209 2007/01/2511:53:51 petere Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1481,7 +1481,8 @@ transformXmlExpr(ParseState *pstate, XmlExpr *x)
14811481
newe=coerce_to_specific_type(pstate,newe,TEXTOID,
14821482
"XMLROOT");
14831483
else
1484-
newe=coerce_to_boolean(pstate,newe,"XMLROOT");
1484+
newe=coerce_to_specific_type(pstate,newe,INT4OID,
1485+
"XMLROOT");
14851486
break;
14861487
caseIS_DOCUMENT:
14871488
newe=coerce_to_specific_type(pstate,newe,XMLOID,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp