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

Commitec020e1

Browse files
committed
Implement XMLSERIALIZE for real. Analogously, make the xml to text cast
observe the xmloption.Reorganize the representation of the XML option in the parse tree and theAPI to make it easier to manage and understand.Add regression tests for parsing back XML expressions.
1 parent25dc463 commitec020e1

File tree

23 files changed

+344
-99
lines changed

23 files changed

+344
-99
lines changed

‎src/backend/executor/execQual.c

Lines changed: 23 additions & 12 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.211 2007/02/02 00:07:03 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/executor/execQual.c,v 1.212 2007/02/03 14:06:53 petere Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -2834,11 +2834,10 @@ ExecEvalXml(XmlExprState *xmlExpr, ExprContext *econtext,
28342834
{
28352835
ExprState*e;
28362836
text*data;
2837-
boolis_document;
28382837
boolpreserve_whitespace;
28392838

2840-
/* arguments are known to be text, bool, bool */
2841-
Assert(list_length(xmlExpr->args)==3);
2839+
/* arguments are known to be text, bool */
2840+
Assert(list_length(xmlExpr->args)==2);
28422841

28432842
e= (ExprState*)linitial(xmlExpr->args);
28442843
value=ExecEvalExpr(e,econtext,&isnull,NULL);
@@ -2848,20 +2847,14 @@ ExecEvalXml(XmlExprState *xmlExpr, ExprContext *econtext,
28482847

28492848
e= (ExprState*)lsecond(xmlExpr->args);
28502849
value=ExecEvalExpr(e,econtext,&isnull,NULL);
2851-
if (isnull)/* probably can't happen */
2852-
return (Datum)0;
2853-
is_document=DatumGetBool(value);
2854-
2855-
e= (ExprState*)lthird(xmlExpr->args);
2856-
value=ExecEvalExpr(e,econtext,&isnull,NULL);
28572850
if (isnull)/* probably can't happen */
28582851
return (Datum)0;
28592852
preserve_whitespace=DatumGetBool(value);
28602853

28612854
*isNull= false;
28622855

28632856
returnPointerGetDatum(xmlparse(data,
2864-
is_document,
2857+
xexpr->xmloption,
28652858
preserve_whitespace));
28662859
}
28672860
break;
@@ -2900,7 +2893,7 @@ ExecEvalXml(XmlExprState *xmlExpr, ExprContext *econtext,
29002893
text*version;
29012894
intstandalone;
29022895

2903-
/* arguments are known to be xml, text,bool */
2896+
/* arguments are known to be xml, text,int */
29042897
Assert(list_length(xmlExpr->args)==3);
29052898

29062899
e= (ExprState*)linitial(xmlExpr->args);
@@ -2928,6 +2921,24 @@ ExecEvalXml(XmlExprState *xmlExpr, ExprContext *econtext,
29282921
}
29292922
break;
29302923

2924+
caseIS_XMLSERIALIZE:
2925+
{
2926+
ExprState*e;
2927+
2928+
/* argument type is known to be xml */
2929+
Assert(list_length(xmlExpr->args)==1);
2930+
2931+
e= (ExprState*)linitial(xmlExpr->args);
2932+
value=ExecEvalExpr(e,econtext,&isnull,NULL);
2933+
if (isnull)
2934+
return (Datum)0;
2935+
2936+
*isNull= false;
2937+
2938+
returnPointerGetDatum(xmltotext_with_xmloption(DatumGetXmlP(value),xexpr->xmloption));
2939+
}
2940+
break;
2941+
29312942
caseIS_DOCUMENT:
29322943
{
29332944
ExprState*e;

‎src/backend/nodes/copyfuncs.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* Portions Copyright (c) 1994, Regents of the University of California
1616
*
1717
* IDENTIFICATION
18-
* $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.364 2007/01/23 05:07:17 tgl Exp $
18+
* $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.365 2007/02/03 14:06:54 petere Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -1116,6 +1116,9 @@ _copyXmlExpr(XmlExpr *from)
11161116
COPY_NODE_FIELD(named_args);
11171117
COPY_NODE_FIELD(arg_names);
11181118
COPY_NODE_FIELD(args);
1119+
COPY_SCALAR_FIELD(xmloption);
1120+
COPY_SCALAR_FIELD(type);
1121+
COPY_SCALAR_FIELD(typmod);
11191122

11201123
returnnewnode;
11211124
}
@@ -1723,6 +1726,18 @@ _copyLockingClause(LockingClause *from)
17231726
returnnewnode;
17241727
}
17251728

1729+
staticXmlSerialize*
1730+
_copyXmlSerialize(XmlSerialize*from)
1731+
{
1732+
XmlSerialize*newnode=makeNode(XmlSerialize);
1733+
1734+
COPY_SCALAR_FIELD(xmloption);
1735+
COPY_NODE_FIELD(expr);
1736+
COPY_NODE_FIELD(typename);
1737+
1738+
returnnewnode;
1739+
}
1740+
17261741
staticQuery*
17271742
_copyQuery(Query*from)
17281743
{
@@ -3430,6 +3445,9 @@ copyObject(void *from)
34303445
caseT_FuncWithArgs:
34313446
retval=_copyFuncWithArgs(from);
34323447
break;
3448+
caseT_XmlSerialize:
3449+
retval=_copyXmlSerialize(from);
3450+
break;
34333451

34343452
default:
34353453
elog(ERROR,"unrecognized node type: %d", (int)nodeTag(from));

‎src/backend/nodes/equalfuncs.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* Portions Copyright (c) 1994, Regents of the University of California
1919
*
2020
* IDENTIFICATION
21-
* $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.297 2007/01/23 05:07:17 tgl Exp $
21+
* $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.298 2007/02/03 14:06:54 petere Exp $
2222
*
2323
*-------------------------------------------------------------------------
2424
*/
@@ -462,6 +462,9 @@ _equalXmlExpr(XmlExpr *a, XmlExpr *b)
462462
COMPARE_NODE_FIELD(named_args);
463463
COMPARE_NODE_FIELD(arg_names);
464464
COMPARE_NODE_FIELD(args);
465+
COMPARE_SCALAR_FIELD(xmloption);
466+
COMPARE_SCALAR_FIELD(type);
467+
COMPARE_SCALAR_FIELD(typmod);
465468

466469
return true;
467470
}
@@ -1830,6 +1833,15 @@ _equalFkConstraint(FkConstraint *a, FkConstraint *b)
18301833
return true;
18311834
}
18321835

1836+
staticbool
1837+
_equalXmlSerialize(XmlSerialize*a,XmlSerialize*b)
1838+
{
1839+
COMPARE_SCALAR_FIELD(xmloption);
1840+
COMPARE_NODE_FIELD(expr);
1841+
COMPARE_NODE_FIELD(typename);
1842+
1843+
return true;
1844+
}
18331845

18341846
/*
18351847
* Stuff from pg_list.h
@@ -2411,6 +2423,9 @@ equal(void *a, void *b)
24112423
caseT_FuncWithArgs:
24122424
retval=_equalFuncWithArgs(a,b);
24132425
break;
2426+
caseT_XmlSerialize:
2427+
retval=_equalXmlSerialize(a,b);
2428+
break;
24142429

24152430
default:
24162431
elog(ERROR,"unrecognized node type: %d",

‎src/backend/nodes/outfuncs.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.295 2007/01/22 20:00:39 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.296 2007/02/03 14:06:54 petere Exp $
1212
*
1313
* NOTES
1414
* Every node type that can appear in stored rules' parsetrees *must*
@@ -933,6 +933,9 @@ _outXmlExpr(StringInfo str, XmlExpr *node)
933933
WRITE_NODE_FIELD(named_args);
934934
WRITE_NODE_FIELD(arg_names);
935935
WRITE_NODE_FIELD(args);
936+
WRITE_ENUM_FIELD(xmloption,XmlOptionType);
937+
WRITE_OID_FIELD(type);
938+
WRITE_INT_FIELD(typmod);
936939
}
937940

938941
staticvoid
@@ -1521,6 +1524,16 @@ _outLockingClause(StringInfo str, LockingClause *node)
15211524
WRITE_BOOL_FIELD(noWait);
15221525
}
15231526

1527+
staticvoid
1528+
_outXmlSerialize(StringInfostr,XmlSerialize*node)
1529+
{
1530+
WRITE_NODE_TYPE("XMLSERIALIZE");
1531+
1532+
WRITE_ENUM_FIELD(xmloption,XmlOptionType);
1533+
WRITE_NODE_FIELD(expr);
1534+
WRITE_NODE_FIELD(typename);
1535+
}
1536+
15241537
staticvoid
15251538
_outColumnDef(StringInfostr,ColumnDef*node)
15261539
{
@@ -2290,6 +2303,9 @@ _outNode(StringInfo str, void *obj)
22902303
caseT_LockingClause:
22912304
_outLockingClause(str,obj);
22922305
break;
2306+
caseT_XmlSerialize:
2307+
_outXmlSerialize(str,obj);
2308+
break;
22932309

22942310
default:
22952311

‎src/backend/nodes/readfuncs.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/nodes/readfuncs.c,v 1.201 2007/01/09 02:14:12 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/nodes/readfuncs.c,v 1.202 2007/02/0314:06:54 petere Exp $
1212
*
1313
* NOTES
1414
* Path and Plan nodes do not have any readfuncs support, because we
@@ -723,6 +723,9 @@ _readXmlExpr(void)
723723
READ_NODE_FIELD(named_args);
724724
READ_NODE_FIELD(arg_names);
725725
READ_NODE_FIELD(args);
726+
READ_ENUM_FIELD(xmloption,XmlOptionType);
727+
READ_OID_FIELD(type);
728+
READ_INT_FIELD(typmod);
726729

727730
READ_DONE();
728731
}

‎src/backend/parser/gram.y

Lines changed: 18 additions & 21 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.578 2007/02/01 19:10:27 momjian Exp $
14+
* $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.579 2007/02/03 14:06:54 petere Exp $
1515
*
1616
* HISTORY
1717
* AUTHORDATEMAJOR EVENT
@@ -350,7 +350,8 @@ static Node *makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args)
350350
%type<target>xml_attribute_el
351351
%type<list>xml_attribute_listxml_attributes
352352
%type<node>xml_root_versionopt_xml_root_standalone
353-
%type<boolean>document_or_contentxml_whitespace_option
353+
%type<ival>document_or_content
354+
%type<boolean>xml_whitespace_option
354355

355356

356357
/*
@@ -1117,7 +1118,7 @@ set_rest: var_name TO var_list_or_default
11171118
{
11181119
VariableSetStmt *n = makeNode(VariableSetStmt);
11191120
n->name ="xmloption";
1120-
n->args = list_make1(makeStringConst($3 ?"DOCUMENT" :"CONTENT",NULL));
1121+
n->args = list_make1(makeStringConst($3== XMLOPTION_DOCUMENT?"DOCUMENT" :"CONTENT",NULL));
11211122
$$ = n;
11221123
}
11231124
;
@@ -7903,10 +7904,11 @@ func_expr:func_name '(' ')'
79037904
}
79047905
| XMLPARSE'(' document_or_content a_expr xml_whitespace_option')'
79057906
{
7906-
$$ = makeXmlExpr(IS_XMLPARSE,NULL, NIL,
7907-
list_make3($4,
7908-
makeBoolAConst($3),
7909-
makeBoolAConst($5)));
7907+
XmlExpr *x = (XmlExpr *) makeXmlExpr(IS_XMLPARSE,NULL, NIL,
7908+
list_make2($4,
7909+
makeBoolAConst($5)));
7910+
x->xmloption = $3;
7911+
$$ = (Node *)x;
79107912
}
79117913
| XMLPI'(' NAME_P ColLabel')'
79127914
{
@@ -7921,14 +7923,13 @@ func_expr:func_name '(' ')'
79217923
$$ = makeXmlExpr(IS_XMLROOT,NULL, NIL,
79227924
list_make3($3, $5, $6));
79237925
}
7924-
| XMLSERIALIZE'(' document_or_content a_expr ASTypename')'
7926+
| XMLSERIALIZE'(' document_or_content a_expr ASSimpleTypename')'
79257927
{
7926-
/*
7927-
* FIXME: This should be made distinguishable from
7928-
* CAST (for reverse compilation at least). Also,
7929-
* what about the document/content option??
7930-
*/
7931-
$$ =makeTypeCast($4, $6);
7928+
XmlSerialize *n = makeNode(XmlSerialize);
7929+
n->xmloption =$3;
7930+
n->expr =$4;
7931+
n->typename =$6;
7932+
$$ = (Node *)n;
79327933
}
79337934
;
79347935

@@ -7980,17 +7981,13 @@ xml_attribute_el: a_expr AS ColLabel
79807981
}
79817982
;
79827983

7983-
document_or_content: DOCUMENT_P{ $$ =TRUE; }
7984-
| CONTENT_P{ $$ =FALSE; }
7984+
document_or_content: DOCUMENT_P{$$ =XMLOPTION_DOCUMENT; }
7985+
| CONTENT_P{$$ =XMLOPTION_CONTENT; }
79857986
;
79867987

7987-
/*
7988-
* XXX per SQL spec, the default should be STRIP WHITESPACE, but since we
7989-
* haven't implemented that yet, temporarily default to PRESERVE.
7990-
*/
79917988
xml_whitespace_option: PRESERVE WHITESPACE_P{$$ =TRUE; }
79927989
| STRIP_P WHITESPACE_P{$$ =FALSE; }
7993-
|/*EMPTY*/{ $$ =TRUE; }
7990+
|/*EMPTY*/{$$ =FALSE; }
79947991
;
79957992

79967993
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp