Skip to content

Commit 0d5cc58

Browse files
committed
fixes #88
1 parent e8a18cc commit 0d5cc58

File tree

3 files changed

+121
-103
lines changed

3 files changed

+121
-103
lines changed

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

Lines changed: 110 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -28,106 +28,119 @@
2828
*/
2929
public class Function implements Expression {
3030

31-
private String name;
32-
private ExpressionList parameters;
33-
private boolean allColumns = false;
34-
private boolean distinct = false;
35-
private boolean isEscaped = false;
36-
37-
@Override
38-
public void accept(ExpressionVisitor expressionVisitor) {
39-
expressionVisitor.visit(this);
40-
}
41-
42-
/**
43-
* The name of he function, i.e. "MAX"
44-
*
45-
* @return the name of he function
46-
*/
47-
public String getName() {
48-
return name;
49-
}
50-
51-
public void setName(String string) {
52-
name = string;
53-
}
54-
55-
/**
56-
* true if the parameter to the function is "*"
57-
*
58-
* @return true if the parameter to the function is "*"
59-
*/
60-
public boolean isAllColumns() {
61-
return allColumns;
62-
}
63-
64-
public void setAllColumns(boolean b) {
65-
allColumns = b;
66-
}
67-
68-
/**
69-
* true if the function is "distinct"
70-
*
71-
* @return true if the function is "distinct"
72-
*/
73-
public boolean isDistinct() {
74-
return distinct;
75-
}
76-
77-
public void setDistinct(boolean b) {
78-
distinct = b;
79-
}
80-
81-
/**
82-
* The list of parameters of the function (if any, else null) If the
83-
* parameter is "*", allColumns is set to true
84-
*
85-
* @return the list of parameters of the function (if any, else null)
86-
*/
87-
public ExpressionList getParameters() {
88-
return parameters;
89-
}
90-
91-
public void setParameters(ExpressionList list) {
92-
parameters = list;
93-
}
94-
95-
/**
96-
* Return true if it's in the form "{fn function_body() }"
97-
*
98-
* @return true if it's java-escaped
99-
*/
100-
public boolean isEscaped() {
101-
return isEscaped;
102-
}
103-
104-
public void setEscaped(boolean isEscaped) {
105-
this.isEscaped = isEscaped;
106-
}
107-
108-
@Override
109-
public String toString() {
110-
String params;
111-
112-
if (parameters != null) {
113-
params = parameters.toString();
114-
if (isDistinct()) {
115-
params = params.replaceFirst("\\(", "(DISTINCT ");
116-
} else if (isAllColumns()) {
31+
private String name;
32+
private ExpressionList parameters;
33+
private boolean allColumns = false;
34+
private boolean distinct = false;
35+
private boolean isEscaped = false;
36+
private String attribute;
37+
38+
@Override
39+
public void accept(ExpressionVisitor expressionVisitor) {
40+
expressionVisitor.visit(this);
41+
}
42+
43+
/**
44+
* The name of he function, i.e. "MAX"
45+
*
46+
* @return the name of he function
47+
*/
48+
public String getName() {
49+
return name;
50+
}
51+
52+
public void setName(String string) {
53+
name = string;
54+
}
55+
56+
/**
57+
* true if the parameter to the function is "*"
58+
*
59+
* @return true if the parameter to the function is "*"
60+
*/
61+
public boolean isAllColumns() {
62+
return allColumns;
63+
}
64+
65+
public void setAllColumns(boolean b) {
66+
allColumns = b;
67+
}
68+
69+
/**
70+
* true if the function is "distinct"
71+
*
72+
* @return true if the function is "distinct"
73+
*/
74+
public boolean isDistinct() {
75+
return distinct;
76+
}
77+
78+
public void setDistinct(boolean b) {
79+
distinct = b;
80+
}
81+
82+
/**
83+
* The list of parameters of the function (if any, else null) If the
84+
* parameter is "*", allColumns is set to true
85+
*
86+
* @return the list of parameters of the function (if any, else null)
87+
*/
88+
public ExpressionList getParameters() {
89+
return parameters;
90+
}
91+
92+
public void setParameters(ExpressionList list) {
93+
parameters = list;
94+
}
95+
96+
/**
97+
* Return true if it's in the form "{fn function_body() }"
98+
*
99+
* @return true if it's java-escaped
100+
*/
101+
public boolean isEscaped() {
102+
return isEscaped;
103+
}
104+
105+
public void setEscaped(boolean isEscaped) {
106+
this.isEscaped = isEscaped;
107+
}
108+
109+
public String getAttribute() {
110+
return attribute;
111+
}
112+
113+
public void setAttribute(String attribute) {
114+
this.attribute = attribute;
115+
}
116+
117+
@Override
118+
public String toString() {
119+
String params;
120+
121+
if (parameters != null) {
122+
params = parameters.toString();
123+
if (isDistinct()) {
124+
params = params.replaceFirst("\\(", "(DISTINCT ");
125+
} else if (isAllColumns()) {
117126
params = params.replaceFirst("\\(", "(ALL ");
118127
}
119-
} else if (isAllColumns()) {
120-
params = "(*)";
121-
} else {
122-
params = "()";
123-
}
128+
} else if (isAllColumns()) {
129+
params = "(*)";
130+
} else {
131+
params = "()";
132+
}
124133

125-
String ans = name + "" + params + "";
134+
String ans = name + "" + params + "";
126135

127-
if (isEscaped) {
128-
ans = "{fn " + ans + "}";
129-
}
136+
if (attribute != null) {
137+
ans += "." + attribute;
138+
}
130139

131-
return ans;
132-
}
140+
if (isEscaped) {
141+
ans = "{fn " + ans + "}";
142+
}
143+
144+
return ans;
145+
}
133146
}

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,10 @@ public void visit(Function function) {
327327
}
328328
}
329329

330+
if (function.getAttribute() != null) {
331+
buffer.append(".").append(function.getAttribute());
332+
}
333+
330334
if (function.isEscaped()) {
331335
buffer.append("}");
332336
}
@@ -502,14 +506,13 @@ public void visit(RegExpMatchOperator rexpr) {
502506
}
503507

504508
@Override
505-
public void visit(RegExpMySQLOperator rexpr) {
506-
visitBinaryExpression(rexpr, " " + rexpr.getStringExpression() + " ");
507-
}
508-
509+
public void visit(RegExpMySQLOperator rexpr) {
510+
visitBinaryExpression(rexpr, " " + rexpr.getStringExpression() + " ");
511+
}
512+
509513
@Override
510514
public void visit(JsonExpression jsonExpr) {
511515
buffer.append(jsonExpr.toString());
512516
}
513517

514-
515518
}

src/main/javacc/net/sf/jsqlparser/parser/JSqlParserCC.jj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
options{
2424
IGNORE_CASE=true ;
2525
STATIC=false;
26-
DEBUG_PARSER=true;
26+
DEBUG_PARSER=false;
2727
DEBUG_LOOKAHEAD=false;
2828
DEBUG_TOKEN_MANAGER=false;
2929
// FORCE_LA_CHECK=true;
@@ -2035,6 +2035,8 @@ Function Function():
20352035
[ "." tmp=RelObjectName() { funcName+= "." + tmp; } ["." tmp=RelObjectName() { funcName+= "." + tmp; }]]
20362036
"(" [ [<K_DISTINCT> { retval.setDistinct(true); } | <K_ALL> { retval.setAllColumns(true); }] (expressionList=SimpleExpressionList() | "*" { retval.setAllColumns(true); }) ] ")"
20372037

2038+
[ "." tmp=RelObjectName() { retval.setAttribute(tmp); }]
2039+
20382040
["}"]
20392041
{
20402042
retval.setParameters(expressionList);

0 commit comments

Comments
 (0)