Skip to content

Commit dc1aa88

Browse files
committed
Merge master into token-action
2 parents 48dbd58 + b3cfdac commit dc1aa88

File tree

21 files changed

+514
-47
lines changed

21 files changed

+514
-47
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
**Describe the bug**
11+
A clear and concise description of what the bug is.
12+
13+
**To Reproduce**
14+
Steps to reproduce the behavior:
15+
1. Example SQL
16+
2. Parsing this SQL using JSqlParser with this statements
17+
3. Exception
18+
19+
**Expected behavior**
20+
A clear and concise description of what you expected to happen.
21+
22+
**System**
23+
- Database you are using
24+
- Java Version
25+
- JSqlParser version

ISSUE_TEMPLATE.md

Lines changed: 0 additions & 15 deletions
This file was deleted.

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Please provide feedback on:
2323
* Is there any need for a Java 7 JSqlParser build, or can we move on to at least Java 8? (https://github.com/JSQLParser/JSqlParser/issues/814)
2424

2525
## News
26+
* due to an API change the version will be 3.0
2627
* JSqlParser uses now Java 8 at the minimum
2728
* Released version **2.1** of JSqlParser
2829
* Released version **2.0** of JSqlParser
@@ -60,8 +61,10 @@ To help JSqlParser's development you are encouraged to provide
6061

6162
Also I would like to know about needed examples or documentation stuff.
6263

63-
## Extensions in the latest SNAPSHOT version 2.2
64+
## Extensions in the latest SNAPSHOT version 3.0
6465

66+
* support for **update table1 inner join table2 ...** (API change)
67+
* support for **declare** statement
6568
* allow empty double quotes
6669
* allow **year**, **month** ... as column data type for **create table**
6770
* allow **duplicate** as object name

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<modelVersion>4.0.0</modelVersion>
33
<groupId>com.github.jsqlparser</groupId>
44
<artifactId>jsqlparser</artifactId>
5-
<version>2.2-SNAPSHOT</version>
5+
<version>3.0-SNAPSHOT</version>
66
<name>JSQLParser library</name>
77
<inceptionYear>2004</inceptionYear>
88
<organization>
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
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.statement;
11+
12+
import java.util.ArrayList;
13+
import java.util.List;
14+
import net.sf.jsqlparser.expression.Expression;
15+
import net.sf.jsqlparser.expression.UserVariable;
16+
import net.sf.jsqlparser.statement.create.table.ColDataType;
17+
import net.sf.jsqlparser.statement.create.table.ColumnDefinition;
18+
19+
public final class DeclareStatement implements Statement {
20+
21+
private UserVariable userVariable = null;
22+
private DeclareType type = DeclareType.TYPE;
23+
private String typeName;
24+
private List<TypeDefExpr> typeDefExprList = new ArrayList<>();
25+
private List<ColumnDefinition> colDefs = new ArrayList<>();
26+
27+
public DeclareStatement() {
28+
}
29+
30+
public void setUserVariable(UserVariable userVariable) {
31+
this.userVariable = userVariable;
32+
}
33+
34+
public UserVariable getUserVariable() {
35+
return userVariable;
36+
}
37+
38+
public DeclareType getType() {
39+
return type;
40+
}
41+
42+
public String getTypeName() {
43+
return typeName;
44+
}
45+
46+
public void setDeclareType(DeclareType type) {
47+
this.type = type;
48+
}
49+
50+
public void addType(ColDataType colDataType, Expression defaultExpr) {
51+
typeDefExprList.add(new TypeDefExpr(colDataType, defaultExpr));
52+
}
53+
54+
public void addType(UserVariable userVariable, ColDataType colDataType, Expression defaultExpr) {
55+
typeDefExprList.add(new TypeDefExpr(userVariable, colDataType, defaultExpr));
56+
}
57+
58+
public void addColumnDefinition(ColumnDefinition colDef) {
59+
colDefs.add(colDef);
60+
}
61+
62+
public List<ColumnDefinition> getColumnDefinitions() {
63+
return colDefs;
64+
}
65+
66+
public List<TypeDefExpr> getTypeDefinitions() {
67+
return typeDefExprList;
68+
}
69+
70+
public void setTypeName(String typeName) {
71+
this.typeName = typeName;
72+
}
73+
74+
@Override
75+
public String toString() {
76+
StringBuilder b = new StringBuilder("DECLARE ");
77+
if (type == DeclareType.AS) {
78+
b.append(userVariable.toString());
79+
b.append(" AS ").append(typeName);
80+
} else {
81+
if (type == DeclareType.TABLE) {
82+
b.append(userVariable.toString());
83+
b.append(" TABLE (");
84+
for (int i = 0; i < colDefs.size(); i++) {
85+
if (i > 0) {
86+
b.append(", ");
87+
}
88+
b.append(colDefs.get(i).toString());
89+
}
90+
b.append(")");
91+
} else {
92+
for (int i = 0; i < typeDefExprList.size(); i++) {
93+
if (i > 0) {
94+
b.append(", ");
95+
}
96+
final TypeDefExpr type = typeDefExprList.get(i);
97+
if (type.userVariable != null) {
98+
b.append(type.userVariable.toString()).append(" ");
99+
}
100+
b.append(type.colDataType.toString());
101+
if (type.defaultExpr != null) {
102+
b.append(" = ").append(type.defaultExpr.toString());
103+
}
104+
}
105+
}
106+
}
107+
return b.toString();
108+
}
109+
110+
@Override
111+
public void accept(StatementVisitor statementVisitor
112+
) {
113+
statementVisitor.visit(this);
114+
}
115+
116+
public static class TypeDefExpr {
117+
118+
public final UserVariable userVariable;
119+
public final ColDataType colDataType;
120+
public final Expression defaultExpr;
121+
122+
public TypeDefExpr(ColDataType colDataType, Expression defaultExpr) {
123+
this(null, colDataType, defaultExpr);
124+
}
125+
126+
public TypeDefExpr(UserVariable userVariable, ColDataType colDataType, Expression defaultExpr) {
127+
this.userVariable = userVariable;
128+
this.colDataType = colDataType;
129+
this.defaultExpr = defaultExpr;
130+
}
131+
}
132+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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.statement;
11+
12+
/**
13+
*
14+
* @author tobens
15+
*/
16+
public enum DeclareType {
17+
TABLE, AS, TYPE
18+
}

src/main/java/net/sf/jsqlparser/statement/StatementVisitor.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,6 @@ public interface StatementVisitor {
8080
public void visit(ExplainStatement aThis);
8181

8282
public void visit(ShowStatement aThis);
83+
84+
public void visit(DeclareStatement aThis);
8385
}

src/main/java/net/sf/jsqlparser/statement/StatementVisitorAdapter.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,8 @@ public void visit(ExplainStatement aThis) {
151151
@Override
152152
public void visit(ShowStatement aThis) {
153153
}
154+
155+
@Override
156+
public void visit(DeclareStatement aThis) {
157+
}
154158
}

src/main/java/net/sf/jsqlparser/statement/create/view/CreateView.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class CreateView implements Statement {
2525
private boolean materialized = false;
2626
private ForceOption force = ForceOption.NONE;
2727
private TemporaryOption temp = TemporaryOption.NONE;
28+
private boolean withReadOnly = false;
2829

2930
@Override
3031
public void accept(StatementVisitor statementVisitor) {
@@ -90,6 +91,14 @@ public void setTemporary(TemporaryOption temp) {
9091
this.temp = temp;
9192
}
9293

94+
public boolean isWithReadOnly() {
95+
return withReadOnly;
96+
}
97+
98+
public void setWithReadOnly(boolean withReadOnly) {
99+
this.withReadOnly = withReadOnly;
100+
}
101+
93102
@Override
94103
public String toString() {
95104
StringBuilder sql = new StringBuilder("CREATE ");
@@ -104,11 +113,11 @@ public String toString() {
104113
sql.append("NO FORCE ");
105114
break;
106115
}
107-
116+
108117
if (temp != TemporaryOption.NONE) {
109118
sql.append(temp.name()).append(" ");
110119
}
111-
120+
112121
if (isMaterialized()) {
113122
sql.append("MATERIALIZED ");
114123
}
@@ -118,6 +127,9 @@ public String toString() {
118127
sql.append(PlainSelect.getStringList(columnNames, true, true));
119128
}
120129
sql.append(" AS ").append(select);
130+
if (isWithReadOnly()) {
131+
sql.append(" WITH READ ONLY");
132+
}
121133
return sql.toString();
122134
}
123135
}

src/main/java/net/sf/jsqlparser/statement/select/SubJoin.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ public String toString() {
6565
StringBuilder sb = new StringBuilder();
6666
sb.append("(").append(left);
6767
for (Join j : joinList) {
68-
sb.append(" ").append(j);
68+
if (j.isSimple()) {
69+
sb.append(", ").append(j);
70+
} else {
71+
sb.append(" ").append(j);
72+
}
6973
}
7074

7175
sb.append(")").append((alias != null) ? (" " + alias.toString()) : "").append((pivot != null) ? " " + pivot : "");

0 commit comments

Comments
 (0)