Skip to content

Commit 22c6eb0

Browse files
committed
Merge origin/master
2 parents 30619d8 + c481ce0 commit 22c6eb0

File tree

18 files changed

+272
-54
lines changed

18 files changed

+272
-54
lines changed

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ 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+
* The array parsing is the default behaviour. Square bracket quotation has to be enabled using
27+
a parser flag (**CCJSqlParser.withSquareBracketQuotation**).
28+
* due to an API change the version will be 3.0
2629
* JSqlParser uses now Java 8 at the minimum
2730
* Released version **2.1** of JSqlParser
2831
* Released version **2.0** of JSqlParser
@@ -60,8 +63,11 @@ To help JSqlParser's development you are encouraged to provide
6063

6164
Also I would like to know about needed examples or documentation stuff.
6265

63-
## Extensions in the latest SNAPSHOT version 2.2
66+
## Extensions in the latest SNAPSHOT version 3.0
6467

68+
* support for array constructs using square brackets. This collides with square bracket
69+
quotation of SqlServer. The parser has now a flag to enable this quotation again (**CCJSqlParser.withSquareBracketQuotation**).
70+
* support for **update table1 inner join table2 ...** (API change)
6571
* support for **declare** statement
6672
* allow empty double quotes
6773
* allow **year**, **month** ... as column data type for **create table**
@@ -88,7 +94,7 @@ As the project is a Maven project, building is rather simple by running:
8894

8995
The project requires the following to build:
9096
- Maven
91-
- JDK 1.7 or later. The jar will target JDK 1.6, but the version of the maven-compiler-plugin that JsqlParser uses requires JDK 1.7+
97+
- JDK 8 or later. The jar will target JDK 8, but the version of the maven-compiler-plugin that JsqlParser uses requires JDK 8+
9298

9399
This will produce the jsqlparser-VERSION.jar file in the target/ directory.
94100

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: 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 ArrayExpression extends ASTNodeAccessImpl implements Expression {
15+
16+
private Expression objExpression;
17+
private Expression indexExpression;
18+
19+
public ArrayExpression(Expression objExpression, Expression indexExpression) {
20+
this.objExpression = objExpression;
21+
this.indexExpression = indexExpression;
22+
}
23+
24+
public Expression getObjExpression() {
25+
return objExpression;
26+
}
27+
28+
public void setObjExpression(Expression objExpression) {
29+
this.objExpression = objExpression;
30+
}
31+
32+
public Expression getIndexExpression() {
33+
return indexExpression;
34+
}
35+
36+
public void setIndexExpression(Expression indexExpression) {
37+
this.indexExpression = indexExpression;
38+
}
39+
40+
@Override
41+
public void accept(ExpressionVisitor expressionVisitor) {
42+
expressionVisitor.visit(this);
43+
}
44+
45+
@Override
46+
public String toString() {
47+
return objExpression.toString() + "[" + indexExpression.toString() + "]";
48+
}
49+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,4 +156,6 @@ public interface ExpressionVisitor {
156156

157157
public void visit(SimilarToExpression aThis);
158158

159+
public void visit(ArrayExpression aThis);
160+
159161
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,4 +523,10 @@ public void visit(CollateExpression col) {
523523
public void visit(SimilarToExpression expr) {
524524
visitBinaryExpression(expr);
525525
}
526+
527+
@Override
528+
public void visit(ArrayExpression array) {
529+
array.getObjExpression().accept(this);
530+
array.getIndexExpression().accept(this);
531+
}
526532
}

src/main/java/net/sf/jsqlparser/parser/CCJSqlParserUtil.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import java.io.InputStream;
1313
import java.io.Reader;
14+
import java.util.function.Consumer;
1415
import net.sf.jsqlparser.JSQLParserException;
1516
import net.sf.jsqlparser.expression.Expression;
1617
import net.sf.jsqlparser.statement.Statement;
@@ -36,7 +37,14 @@ public static Statement parse(Reader statementReader) throws JSQLParserException
3637
}
3738

3839
public static Statement parse(String sql) throws JSQLParserException {
40+
return parse(sql, null);
41+
}
42+
43+
public static Statement parse(String sql, Consumer<CCJSqlParser> consumer) throws JSQLParserException {
3944
CCJSqlParser parser = new CCJSqlParser(new StringProvider(sql));
45+
if (consumer != null) {
46+
consumer.accept(parser);
47+
}
4048
try {
4149
return parser.Statement();
4250
} catch (Exception ex) {
@@ -96,7 +104,8 @@ public static Expression parseCondExpression(String condExpr) throws JSQLParserE
96104
}
97105

98106
/**
99-
* Parse an conditional expression. This is the expression after a where clause.
107+
* Parse an conditional expression. This is the expression after a where
108+
* clause.
100109
*
101110
* @param condExpr
102111
* @param allowPartialParse false: needs the whole string to be processed.

src/main/java/net/sf/jsqlparser/parser/SimpleCharStream.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -391,12 +391,22 @@ public char[] GetSuffix(int len) {
391391

392392
char[] ret = new char[len];
393393

394-
if ((bufpos + 1) >= len) {
395-
System.arraycopy(buffer, bufpos - len + 1, ret, 0, len);
394+
if (isStringProvider) {
395+
String str = ((StringProvider) inputStream)._string;
396+
if ((bufpos + 1) >= len) {
397+
str.getChars(bufpos - len + 1, bufpos - len + 1 + len, ret, 0);
398+
} else {
399+
str.getChars(bufsize - (len - bufpos - 1), bufsize - (len - bufpos - 1) + len - bufpos - 1, ret, 0);
400+
str.getChars(0, bufpos + 1, ret, len - bufpos - 1);
401+
}
396402
} else {
397-
System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0,
398-
len - bufpos - 1);
399-
System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1);
403+
if ((bufpos + 1) >= len) {
404+
System.arraycopy(buffer, bufpos - len + 1, ret, 0, len);
405+
} else {
406+
System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0,
407+
len - bufpos - 1);
408+
System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1);
409+
}
400410
}
401411

402412
return ret;

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/update/Update.java

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@
2626

2727
public class Update implements Statement {
2828

29-
private List<Table> tables;
29+
private Table table;
3030
private Expression where;
3131
private List<Column> columns;
3232
private List<Expression> expressions;
3333
private FromItem fromItem;
3434
private List<Join> joins;
35+
private List<Join> startJoins;
3536
private Select select;
3637
private boolean useColumnsBrackets = true;
3738
private boolean useSelect = false;
@@ -45,16 +46,16 @@ public void accept(StatementVisitor statementVisitor) {
4546
statementVisitor.visit(this);
4647
}
4748

48-
public List<Table> getTables() {
49-
return tables;
49+
public Table getTable() {
50+
return table;
5051
}
5152

5253
public Expression getWhere() {
5354
return where;
5455
}
5556

56-
public void setTables(List<Table> list) {
57-
tables = list;
57+
public void setTable(Table table) {
58+
this.table = table;
5859
}
5960

6061
public void setWhere(Expression expression) {
@@ -93,6 +94,14 @@ public void setJoins(List<Join> joins) {
9394
this.joins = joins;
9495
}
9596

97+
public List<Join> getStartJoins() {
98+
return startJoins;
99+
}
100+
101+
public void setStartJoins(List<Join> startJoins) {
102+
this.startJoins = startJoins;
103+
}
104+
96105
public Select getSelect() {
97106
return select;
98107
}
@@ -152,7 +161,17 @@ public void setReturningExpressionList(List<SelectExpressionItem> returningExpre
152161
@Override
153162
public String toString() {
154163
StringBuilder b = new StringBuilder("UPDATE ");
155-
b.append(PlainSelect.getStringList(getTables(), true, false)).append(" SET ");
164+
b.append(table);
165+
if (startJoins != null) {
166+
for (Join join : startJoins) {
167+
if (join.isSimple()) {
168+
b.append(", ").append(join);
169+
} else {
170+
b.append(" ").append(join);
171+
}
172+
}
173+
}
174+
b.append(" SET ");
156175

157176
if (!useSelect) {
158177
for (int i = 0; i < getColumns().size(); i++) {

src/main/java/net/sf/jsqlparser/util/TablesNamesFinder.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import net.sf.jsqlparser.expression.AllComparisonExpression;
1515
import net.sf.jsqlparser.expression.AnalyticExpression;
1616
import net.sf.jsqlparser.expression.AnyComparisonExpression;
17+
import net.sf.jsqlparser.expression.ArrayExpression;
1718
import net.sf.jsqlparser.expression.BinaryExpression;
1819
import net.sf.jsqlparser.expression.CaseExpression;
1920
import net.sf.jsqlparser.expression.CastExpression;
@@ -623,8 +624,11 @@ public void visit(Delete delete) {
623624

624625
@Override
625626
public void visit(Update update) {
626-
for (Table table : update.getTables()) {
627-
visit(table);
627+
visit(update.getTable());
628+
if (update.getStartJoins() != null) {
629+
for (Join join : update.getStartJoins()) {
630+
join.getRightItem().accept(this);
631+
}
628632
}
629633
if (update.getExpressions() != null) {
630634
for (Expression expression : update.getExpressions()) {
@@ -851,4 +855,10 @@ public void visit(SimilarToExpression expr) {
851855
@Override
852856
public void visit(DeclareStatement aThis) {
853857
}
858+
859+
@Override
860+
public void visit(ArrayExpression array) {
861+
array.getObjExpression().accept(this);
862+
array.getIndexExpression().accept(this);
863+
}
854864
}

0 commit comments

Comments
 (0)