Skip to content

Prepare4.2 #1329

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Sep 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,10 @@ jdk:
- openjdk11

after_success:
- mvn clean cobertura:cobertura coveralls:report
- mvn clean cobertura:cobertura coveralls:report

cache:
directories:
- $HOME/.m2
- $HOME/.gradle/caches/
- $HOME/.gradle/wrapper/
36 changes: 29 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,25 @@ To help JSqlParser's development you are encouraged to provide
Also I would like to know about needed examples or documentation stuff.

## Extensions in the latest SNAPSHOT version 4.2

* API change: Support `SELECT ...` without a `FROM` clause, making `SELECT 1, 2` and `SELECT *` parsable statements (before those failed)
* API change: Support complex `UPDATE` sets (using multiple `SubQuery` or `ValueList` or Single Values, in combination)
* Support nested `CASE` expressions with complex expression arguments
* API change: Support `JOIN` with multiple trailing `ON` Expressions (`JOIN ... JOIN ... ON ... ON ...`)
* Support Oracle Hierarchical `CONNECT_BY_ROOT` Operator
* Support Transact-SQL `IF ... ELSE ...` Statement Control Flows.
* Allow optional parameters for the `ALTER TABLE ...` statement (e.g. `ALTER TABLE ... MOVE TABLESPACE ...`)
* Support Oracle `ALTER SYSTEM ...` statement
* Support Oracle Named Function Parameters`Func( param1 => arg1, ...`
* Add Gradle build
* Allow `JdbcParameter` or `JdbcNamedParameter` for MySQL FullTextSearch
* Allow `Cast` into `Row` Constructor
* Support Oracle `RENAME ... TO ...` statement
* Support Oracle `PURGE` statement
* Support JSON functions `JSON_OBJECT()`, `JSON_ARRAY()`, `JSON_OBJECTAGG()`, `JSON_ARRAYAGG()`
* API change: merge ALL and ANY expressions class
* allow `CURRENT DATE`in addition to `CURRENT_DATE` (without underbar)
* Allow DB2 compliant `CURRENT DATE`in addition to `CURRENT_DATE` (without underscore)

Additionally, we have fixed many errors and improved the code quality and the test coverage.

## Extensions of JSqlParser releases

Expand All @@ -67,16 +83,22 @@ Also I would like to know about needed examples or documentation stuff.
## Building from the sources

As the project is a Maven project, building is rather simple by running:
```shell
mvn package
```

mvn package
Since 4.2, alternatively Gradle can be used
```shell
gradle build
```

The project requires the following to build:
- Maven
- Maven (or Gradle)
- JDK 8 or later. The jar will target JDK 8, but the version of the maven-compiler-plugin that JsqlParser uses requires JDK 8+

This will produce the jsqlparser-VERSION.jar file in the target/ directory.
This will produce the jsqlparser-VERSION.jar file in the `target/` directory (`build/libs/jsqlparser-VERSION.jar` in case of Gradle).

**To build this project without using Maven, one has to build the parser by JavaCC using the CLI options it provides.**
**To build this project without using Maven or Gradle, one has to build the parser by JavaCC using the CLI options it provides.**

## Debugging through problems

Expand Down Expand Up @@ -124,7 +146,7 @@ And this is the dependency declaration in your pom:
<dependency>
<groupId>com.github.jsqlparser</groupId>
<artifactId>jsqlparser</artifactId>
<version>4.0</version>
<version>4.1</version>
</dependency>
```

2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jacocoTestCoverageVerification {
violationRules {
rule {
limit {
minimum = 0.837
minimum = 0.838
}
}
}
Expand Down
40 changes: 11 additions & 29 deletions src/main/java/net/sf/jsqlparser/statement/update/Update.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,12 @@ public void setSelect(Select select) {

@Deprecated
public boolean isUseColumnsBrackets() {
return updateSets.get(0).usingBrackets;
return updateSets.get(0).usingBracketsForColumns;
}

@Deprecated
public void setUseColumnsBrackets(boolean useColumnsBrackets) {
updateSets.get(0).usingBrackets = useColumnsBrackets;
updateSets.get(0).usingBracketsForColumns = useColumnsBrackets;
}

@Deprecated
Expand Down Expand Up @@ -268,7 +268,7 @@ public String toString() {
b.append(", ");
}

if (updateSet.usingBrackets) {
if (updateSet.usingBracketsForColumns) {
b.append("(");
}

Expand All @@ -279,46 +279,28 @@ public String toString() {
b.append(updateSet.columns.get(i));
}

if (updateSet.usingBrackets) {
if (updateSet.usingBracketsForColumns) {
b.append(")");
}

b.append(" = ");

if (updateSet.usingBracketsForValues) {
b.append("(");
}

for (int i = 0; i < updateSet.expressions.size(); i++) {
if (i > 0) {
b.append(", ");
}
b.append(updateSet.expressions.get(i));
}
if (updateSet.usingBracketsForValues) {
b.append(")");
}

j++;
}

// if (!useSelect) {
// for (int i = 0; i < getColumns().size(); i++) {
// if (i != 0) {
// b.append(", ");
// }
// b.append(columns.get(i)).append(" = ");
// b.append(expressions.get(i));
// }
// } else {
// if (useColumnsBrackets) {
// b.append("(");
// }
// for (int i = 0; i < getColumns().size(); i++) {
// if (i != 0) {
// b.append(", ");
// }
// b.append(columns.get(i));
// }
// if (useColumnsBrackets) {
// b.append(")");
// }
// b.append(" = ");
// b.append("(").append(select).append(")");
// }
if (fromItem != null) {
b.append(" FROM ").append(fromItem);
if (joins != null) {
Expand Down
30 changes: 22 additions & 8 deletions src/main/java/net/sf/jsqlparser/statement/update/UpdateSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
import java.util.Objects;

public class UpdateSet {
protected boolean usingBrackets = false;
protected boolean usingBracketsForColumns = false;
protected boolean usingBracketsForValues = false;
protected ArrayList<Column> columns = new ArrayList<>();
protected ArrayList<Expression> expressions = new ArrayList<>();

Expand All @@ -34,12 +35,20 @@ public UpdateSet(Column column, Expression expression) {
this.expressions.add(expression);
}

public boolean isUsingBrackets() {
return usingBrackets;
public boolean isUsingBracketsForValues() {
return usingBracketsForValues;
}

public void setUsingBrackets(boolean usingBrackets) {
this.usingBrackets = usingBrackets;
public void setUsingBracketsForValues(boolean usingBracketsForValues) {
this.usingBracketsForValues = usingBracketsForValues;
}

public boolean isUsingBracketsForColumns() {
return usingBracketsForColumns;
}

public void setUsingBracketsForColumns(boolean usingBracketsForColumns) {
this.usingBracketsForColumns = usingBracketsForColumns;
}

public ArrayList<Column> getColumns() {
Expand All @@ -61,13 +70,18 @@ public void setExpressions(ArrayList<Expression> expressions) {
public void add(Column column, Expression expression) {
columns.add(column);
expressions.add(expression);
};
}

public void add(Column column) {
columns.add(column);
};
}

public void add(Expression expression) {
expressions.add(expression);
}

public void add(ExpressionList expressionList) {
expressions.addAll(expressionList.getExpressions());
};
}

}
45 changes: 8 additions & 37 deletions src/main/java/net/sf/jsqlparser/util/deparser/UpdateDeParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void deParse(Update update) {
buffer.append(", ");
}

if (updateSet.isUsingBrackets()) {
if (updateSet.isUsingBracketsForColumns()) {
buffer.append("(");
}
for (int i = 0; i < updateSet.getColumns().size(); i++) {
Expand All @@ -75,56 +75,27 @@ public void deParse(Update update) {
}
updateSet.getColumns().get(i).accept(expressionVisitor);
}
if (updateSet.isUsingBrackets()) {
if (updateSet.isUsingBracketsForColumns()) {
buffer.append(")");
}

buffer.append(" = ");

if (updateSet.isUsingBracketsForValues()) {
buffer.append("(");
}
for (int i = 0; i < updateSet.getExpressions().size(); i++) {
if (i > 0) {
buffer.append(", ");
}
updateSet.getExpressions().get(i).accept(expressionVisitor);
}
if (updateSet.isUsingBracketsForValues()) {
buffer.append(")");
}

j++;
}

// if (!update.isUseSelect()) {
// for (int i = 0; i < update.getColumns().size(); i++) {
// Column column = update.getColumns().get(i);
// column.accept(expressionVisitor);
//
// buffer.append(" = ");
//
// Expression expression = update.getExpressions().get(i);
// expression.accept(expressionVisitor);
// if (i < update.getColumns().size() - 1) {
// buffer.append(", ");
// }
// }
// } else {
// if (update.isUseColumnsBrackets()) {
// buffer.append("(");
// }
// for (int i = 0; i < update.getColumns().size(); i++) {
// if (i != 0) {
// buffer.append(", ");
// }
// Column column = update.getColumns().get(i);
// column.accept(expressionVisitor);
// }
// if (update.isUseColumnsBrackets()) {
// buffer.append(")");
// }
// buffer.append(" = ");
// buffer.append("(");
// Select select = update.getSelect();
// select.getSelectBody().accept(selectVisitor);
// buffer.append(")");
// }

if (update.getFromItem() != null) {
buffer.append(" FROM ").append(update.getFromItem());
if (update.getJoins() != null) {
Expand Down
Loading