Skip to content

Commit 8c4e0ca

Browse files
committed
xmlserialize support patch for expressions
1 parent abedce5 commit 8c4e0ca

File tree

5 files changed

+21
-12
lines changed

5 files changed

+21
-12
lines changed

src/main/java/net/sf/jsqlparser/expression/ExpressionVisitorAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ public void visit(VariableAssignment var) {
550550

551551
@Override
552552
public void visit(XMLSerializeExpr expr) {
553-
expr.getColumn().accept(this);
553+
expr.getExpression().accept(this);
554554
for (OrderByElement elm : expr.getOrderByElements()) {
555555
elm.getExpression().accept(this);
556556
}

src/main/java/net/sf/jsqlparser/expression/XMLSerializeExpr.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,12 @@
1212
import java.util.List;
1313
import static java.util.stream.Collectors.joining;
1414
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
15-
import net.sf.jsqlparser.schema.Column;
1615
import net.sf.jsqlparser.statement.create.table.ColDataType;
1716
import net.sf.jsqlparser.statement.select.OrderByElement;
1817

1918
public class XMLSerializeExpr extends ASTNodeAccessImpl implements Expression {
2019

21-
private Column column;
20+
private Expression expression;
2221
private List<OrderByElement> orderByElements;
2322
private ColDataType dataType;
2423

@@ -27,12 +26,12 @@ public void accept(ExpressionVisitor expressionVisitor) {
2726
expressionVisitor.visit(this);
2827
}
2928

30-
public Column getColumn() {
31-
return column;
29+
public Expression getExpression() {
30+
return expression;
3231
}
3332

34-
public void setColumn(Column column) {
35-
this.column = column;
33+
public void setExpression(Expression expression) {
34+
this.expression = expression;
3635
}
3736

3837
public List<OrderByElement> getOrderByElements() {
@@ -53,7 +52,7 @@ public void setDataType(ColDataType dataType) {
5352

5453
@Override
5554
public String toString() {
56-
return "xmlserialize(xmlagg(xmltext(" + column + ") ORDER BY " +
55+
return "xmlserialize(xmlagg(xmltext(" + expression + ") ORDER BY " +
5756
orderByElements.stream().map(item -> item.toString()).collect(joining(", ")) +
5857
") AS " + dataType + ")";
5958
}

src/main/java/net/sf/jsqlparser/util/deparser/ExpressionDeParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,7 @@ public void visit(VariableAssignment var) {
907907
public void visit(XMLSerializeExpr expr) {
908908
//xmlserialize(xmlagg(xmltext(COMMENT_LINE) ORDER BY COMMENT_SEQUENCE) as varchar(1024))
909909
buffer.append("xmlserialize(xmlagg(xmltext(");
910-
expr.getColumn().accept(this);
910+
expr.getExpression().accept(this);
911911
buffer.append(") ORDER BY ");
912912
for (Iterator<OrderByElement> i = expr.getOrderByElements().iterator(); i.hasNext();) {
913913
buffer.append(i.next().toString());

src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3790,20 +3790,20 @@ Function InternalFunction(Function retval) :
37903790

37913791
XMLSerializeExpr XMLSerializeExpr(): {
37923792
XMLSerializeExpr result;
3793-
Column column;
3793+
Expression expression;
37943794
List<OrderByElement> orderByElements;
37953795
ColDataType dataType;
37963796
}
37973797
{
37983798
<K_XMLSERIALIZE>
37993799
"(" <K_XMLAGG>
38003800
"(" <K_XMLTEXT>
3801-
"(" column=Column() ")"
3801+
"(" expression=SimpleExpression() ")"
38023802
orderByElements=OrderByElements() ")"
38033803
<K_AS> dataType=ColDataType() ")"
38043804
{
38053805
result = new XMLSerializeExpr();
3806-
result.setColumn(column);
3806+
result.setExpression(expression);
38073807
result.setOrderByElements(orderByElements);
38083808
result.setDataType(dataType);
38093809
return result;

src/test/java/net/sf/jsqlparser/statement/select/SelectXMLSerializeTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,14 @@ public void testXmlAgg2() throws JSQLParserException {
3232
public void testXmlAgg3() throws JSQLParserException {
3333
assertSqlCanBeParsedAndDeparsed("SELECT xmlserialize(xmlagg(xmltext(COMMENT_LINE) ORDER BY COMMENT_SEQUENCE) AS varchar (1024))");
3434
}
35+
36+
@Test
37+
public void testXmlAgg4() throws JSQLParserException {
38+
assertSqlCanBeParsedAndDeparsed("SELECT xmlserialize(xmlagg(xmltext(COMMENT_LINE_PREFIX || COMMENT_LINE) ORDER BY COMMENT_SEQUENCE) AS varchar (1024))");
39+
}
40+
41+
@Test
42+
public void testXmlAgg5() throws JSQLParserException {
43+
assertSqlCanBeParsedAndDeparsed("SELECT xmlserialize(xmlagg(xmltext(CONCAT(', ', TRIM(SOME_COLUMN))) ORDER BY MY_SEQUENCE) AS varchar (1024))");
44+
}
3545
}

0 commit comments

Comments
 (0)