Skip to content

Commit 7082c6a

Browse files
committed
Merge origin/master
2 parents 46323b4 + 67dce2f commit 7082c6a

25 files changed

+990
-163
lines changed

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ JSqlParser is dual licensed under **LGPL V2.1** or **Apache Software License, Ve
2222
Please provide feedback on https://github.com/JSQLParser/JSqlParser/issues/677, about removing bracket identifier quotation to support array processing.
2323

2424
## News
25+
* breaking **API** change: to support chained functions attribute type was changed to **Expression**
2526
* Released version **1.4** of JSqlParser
2627
* Released version **1.3** of JSqlParser
2728
* Changed behaviour of dotted multipart names for user variables, tables and columns to accept e.g. ORM class names. To achieve this some behaviour of name parsing had to be changed. Before this the parser would fail missing databasenames for SqlServer queries (server..schema.table). But this is allowed for the schema (server.database..table). Now the parser accepts missing inner names per se to avoid some very complicated parsing rules.
@@ -33,6 +34,9 @@ Please provide feedback on https://github.com/JSQLParser/JSqlParser/issues/677,
3334

3435
More news can be found here: https://github.com/JSQLParser/JSqlParser/wiki/News.
3536

37+
## Alternatives to JSqlParser?
38+
[**General SQL Parser**](http://www.sqlparser.com/features/introduce.php?utm_source=github-jsqlparser&utm_medium=text-general) looks pretty good, with extended SQL syntax (like PL/SQL and T-SQL) and java + .NET APIs. The tool is commercial (license available online), with a free download option.
39+
3640
## JSqlParser
3741

3842
JSqlParser is a SQL statement parser. It translates SQLs in a traversable hierarchy of Java classes. JSqlParser is not limited to one database but provides support for a lot of specials of Oracle, SqlServer, MySQL, PostgreSQL ... To name some, it has support for Oracles join syntax using (+), PostgreSQLs cast syntax using ::, relational operators like != and so on.
@@ -55,6 +59,11 @@ Also I would like to know about needed examples or documentation stuff.
5559

5660
## Extensions in the latest SNAPSHOT version 2.0
5761

62+
* support for **GROUPING SETS**
63+
* first support for db date arithmetic
64+
* support for chained functions
65+
* first support for **FOR XML PATH**
66+
* support for **NEXTVAL FOR**
5867
* changed all source code license headers to reflect the dual license of JSqlParser more correctly
5968
* support of **OPTIMIZE FOR 20 ROWS** like expressions
6069
* allowed conditions within **then** and **else** of a **case** statement
@@ -133,7 +142,7 @@ And this is the dependency declaration in your pom:
133142
<dependency>
134143
<groupId>com.github.jsqlparser</groupId>
135144
<artifactId>jsqlparser</artifactId>
136-
<version>1.2</version>
145+
<version>1.4</version>
137146
</dependency>
138147
```
139148

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*-
2+
* #%L
3+
* JSQLParser library
4+
* %%
5+
* Copyright (C) 2004 - 2019 JSQLParser
6+
* %%
7+
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
8+
* #L%
9+
*/
10+
package net.sf.jsqlparser.expression;
11+
12+
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
13+
14+
public class CollateExpression extends ASTNodeAccessImpl implements Expression {
15+
16+
private Expression leftExpression;
17+
private String collate;
18+
19+
public CollateExpression(Expression leftExpression, String collate) {
20+
this.leftExpression = leftExpression;
21+
this.collate = collate;
22+
}
23+
24+
@Override
25+
public void accept(ExpressionVisitor expressionVisitor) {
26+
expressionVisitor.visit(this);
27+
}
28+
29+
public Expression getLeftExpression() {
30+
return leftExpression;
31+
}
32+
33+
public void setLeftExpression(Expression leftExpression) {
34+
this.leftExpression = leftExpression;
35+
}
36+
37+
public String getCollate() {
38+
return collate;
39+
}
40+
41+
public void setCollate(String collate) {
42+
this.collate = collate;
43+
}
44+
45+
@Override
46+
public String toString() {
47+
return leftExpression.toString() + " COLLATE " + collate;
48+
}
49+
}

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@
2929
import net.sf.jsqlparser.expression.operators.relational.GreaterThanEquals;
3030
import net.sf.jsqlparser.expression.operators.relational.InExpression;
3131
import net.sf.jsqlparser.expression.operators.relational.IsNullExpression;
32+
import net.sf.jsqlparser.expression.operators.relational.JsonOperator;
3233
import net.sf.jsqlparser.expression.operators.relational.LikeExpression;
3334
import net.sf.jsqlparser.expression.operators.relational.Matches;
3435
import net.sf.jsqlparser.expression.operators.relational.MinorThan;
3536
import net.sf.jsqlparser.expression.operators.relational.MinorThanEquals;
3637
import net.sf.jsqlparser.expression.operators.relational.NotEqualsTo;
3738
import net.sf.jsqlparser.expression.operators.relational.RegExpMatchOperator;
3839
import net.sf.jsqlparser.expression.operators.relational.RegExpMySQLOperator;
39-
import net.sf.jsqlparser.expression.operators.relational.JsonOperator;
4040
import net.sf.jsqlparser.schema.Column;
4141
import net.sf.jsqlparser.statement.select.SubSelect;
4242

@@ -155,7 +155,7 @@ public interface ExpressionVisitor {
155155
void visit(KeepExpression aexpr);
156156

157157
void visit(MySQLGroupConcat groupConcat);
158-
158+
159159
void visit(ValueListExpression valueList);
160160

161161
void visit(RowConstructor rowConstructor);
@@ -168,4 +168,8 @@ public interface ExpressionVisitor {
168168

169169
public void visit(NotExpression aThis);
170170

171+
public void visit(NextValExpression aThis);
172+
173+
public void visit(CollateExpression aThis);
174+
171175
}

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import net.sf.jsqlparser.expression.operators.arithmetic.*;
1313
import net.sf.jsqlparser.expression.operators.conditional.AndExpression;
1414
import net.sf.jsqlparser.expression.operators.conditional.OrExpression;
15-
import net.sf.jsqlparser.expression.operators.relational.JsonOperator;
1615
import net.sf.jsqlparser.expression.operators.relational.*;
1716
import net.sf.jsqlparser.schema.Column;
1817
import net.sf.jsqlparser.statement.select.AllColumns;
@@ -341,7 +340,6 @@ public void visit(NamedExpressionList namedExpressionList) {
341340
}
342341
}
343342

344-
345343
@Override
346344
public void visit(MultiExpressionList multiExprList) {
347345
for (ExpressionList list : multiExprList.getExprList()) {
@@ -412,7 +410,7 @@ public void visit(MySQLGroupConcat groupConcat) {
412410
}
413411
}
414412
}
415-
413+
416414
@Override
417415
public void visit(ValueListExpression valueListExpression) {
418416
for (Expression expr : valueListExpression.getExpressionList().getExpressions()) {
@@ -493,7 +491,14 @@ public void visit(TimeKeyExpression timeKeyExpression) {
493491

494492
@Override
495493
public void visit(DateTimeLiteralExpression literal) {
494+
}
496495

496+
@Override
497+
public void visit(NextValExpression nextVal) {
497498
}
498499

500+
@Override
501+
public void visit(CollateExpression col) {
502+
col.getLeftExpression().accept(this);
503+
}
499504
}

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

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ public class Function extends ASTNodeAccessImpl implements Expression {
2121
private boolean allColumns = false;
2222
private boolean distinct = false;
2323
private boolean isEscaped = false;
24-
private String attribute;
24+
private Expression attribute;
25+
private String attributeName;
2526
private KeepExpression keep = null;
2627

2728
@Override
@@ -77,7 +78,6 @@ public void setParameters(ExpressionList list) {
7778
*
7879
* @return the list of named parameters of the function (if any, else null)
7980
*/
80-
8181
public NamedExpressionList getNamedParameters() {
8282
return namedParameters;
8383
}
@@ -99,14 +99,22 @@ public void setEscaped(boolean isEscaped) {
9999
this.isEscaped = isEscaped;
100100
}
101101

102-
public String getAttribute() {
102+
public Expression getAttribute() {
103103
return attribute;
104104
}
105105

106-
public void setAttribute(String attribute) {
106+
public void setAttribute(Expression attribute) {
107107
this.attribute = attribute;
108108
}
109109

110+
public String getAttributeName() {
111+
return attributeName;
112+
}
113+
114+
public void setAttributeName(String attributeName) {
115+
this.attributeName = attributeName;
116+
}
117+
110118
public KeepExpression getKeep() {
111119
return keep;
112120
}
@@ -120,14 +128,14 @@ public String toString() {
120128
String params;
121129

122130
if (parameters != null || namedParameters != null) {
123-
if(parameters != null){
131+
if (parameters != null) {
124132
params = parameters.toString();
125133
if (isDistinct()) {
126134
params = params.replaceFirst("\\(", "(DISTINCT ");
127135
} else if (isAllColumns()) {
128136
params = params.replaceFirst("\\(", "(ALL ");
129137
}
130-
} else{
138+
} else {
131139
params = namedParameters.toString();
132140
}
133141
} else if (isAllColumns()) {
@@ -139,7 +147,9 @@ public String toString() {
139147
String ans = name + "" + params + "";
140148

141149
if (attribute != null) {
142-
ans += "." + attribute;
150+
ans += "." + attribute.toString();
151+
} else if (attributeName != null) {
152+
ans += "." + attributeName;
143153
}
144154

145155
if (keep != null) {

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,23 @@
99
*/
1010
package net.sf.jsqlparser.expression;
1111

12+
import java.util.Objects;
1213
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
1314

1415
public class IntervalExpression extends ASTNodeAccessImpl implements Expression {
1516

1617
private String parameter = null;
1718
private String intervalType = null;
19+
private final boolean intervalKeyword;
20+
private Expression expression = null;
21+
22+
public IntervalExpression() {
23+
this(true);
24+
}
25+
26+
public IntervalExpression(boolean intervalKeyword) {
27+
this.intervalKeyword = intervalKeyword;
28+
}
1829

1930
public String getParameter() {
2031
return parameter;
@@ -32,9 +43,19 @@ public void setIntervalType(String intervalType) {
3243
this.intervalType = intervalType;
3344
}
3445

46+
public Expression getExpression() {
47+
return expression;
48+
}
49+
50+
public void setExpression(Expression expression) {
51+
this.expression = expression;
52+
}
53+
3554
@Override
3655
public String toString() {
37-
return "INTERVAL " + parameter + (intervalType != null ? " " + intervalType : "");
56+
return (intervalKeyword ? "INTERVAL " : "")
57+
+ Objects.toString(expression, parameter)
58+
+ (intervalType != null ? " " + intervalType : "");
3859
}
3960

4061
@Override
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*-
2+
* #%L
3+
* JSQLParser library
4+
* %%
5+
* Copyright (C) 2004 - 2019 JSQLParser
6+
* %%
7+
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
8+
* #L%
9+
*/
10+
package net.sf.jsqlparser.expression;
11+
12+
import java.util.List;
13+
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
14+
15+
public class NextValExpression extends ASTNodeAccessImpl implements Expression {
16+
17+
private List<String> nameList;
18+
19+
public NextValExpression(List<String> nameList) {
20+
this.nameList = nameList;
21+
}
22+
23+
public String getName() {
24+
StringBuilder b = new StringBuilder();
25+
for (String name : nameList) {
26+
if (b.length() > 0) {
27+
b.append(".");
28+
}
29+
b.append(name);
30+
}
31+
return b.toString();
32+
}
33+
34+
@Override
35+
public String toString() {
36+
return "NEXTVAL FOR " + getName();
37+
}
38+
39+
@Override
40+
public void accept(ExpressionVisitor expressionVisitor) {
41+
expressionVisitor.visit(this);
42+
}
43+
}

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,15 @@ public class NotExpression extends ASTNodeAccessImpl implements Expression {
1515

1616
private Expression expression;
1717

18+
private boolean exclamationMark = false;
19+
1820
public NotExpression(Expression expression) {
21+
this(expression, false);
22+
}
23+
24+
public NotExpression(Expression expression, boolean useExclamationMark) {
1925
setExpression(expression);
26+
this.exclamationMark = useExclamationMark;
2027
}
2128

2229
public Expression getExpression() {
@@ -34,6 +41,14 @@ public void accept(ExpressionVisitor expressionVisitor) {
3441

3542
@Override
3643
public String toString() {
37-
return "NOT " + expression.toString();
44+
return (exclamationMark ? "! " : "NOT ") + expression.toString();
45+
}
46+
47+
public boolean isExclamationMark() {
48+
return exclamationMark;
49+
}
50+
51+
public void setExclamationMark(boolean exclamationMark) {
52+
this.exclamationMark = exclamationMark;
3853
}
3954
}

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
public class Parenthesis extends ASTNodeAccessImpl implements Expression {
1515

1616
private Expression expression;
17-
18-
private boolean not = false;
1917

2018
public Parenthesis() {
2119
}
@@ -37,16 +35,8 @@ public void accept(ExpressionVisitor expressionVisitor) {
3735
expressionVisitor.visit(this);
3836
}
3937

40-
public void setNot() {
41-
not = true;
42-
}
43-
44-
public boolean isNot() {
45-
return not;
46-
}
47-
4838
@Override
4939
public String toString() {
50-
return (not ? "NOT " : "") + "(" + expression + ")";
40+
return "(" + expression + ")";
5141
}
5242
}

0 commit comments

Comments
 (0)