Skip to content
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

Added support for minus all; except all; intersect all; #2081

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
40 changes: 40 additions & 0 deletions src/main/java/net/sf/jsqlparser/statement/select/ExceptOp.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,47 @@

public class ExceptOp extends SetOperation {

private boolean distinct;
private boolean all;

public ExceptOp() {
super(SetOperationType.EXCEPT);
}

public boolean isAll() {
return all;
}

public void setAll(boolean all) {
this.all = all;
}

public boolean isDistinct() {
return distinct;
}

public void setDistinct(boolean distinct) {
this.distinct = distinct;
}

@Override
public String toString() {
String allDistinct = "";
if (isAll()) {
allDistinct = " ALL";
} else if (isDistinct()) {
allDistinct = " DISTINCT";
}
return super.toString() + allDistinct;
}

public ExceptOp withDistinct(boolean distinct) {
this.setDistinct(distinct);
return this;
}

public ExceptOp withAll(boolean all) {
this.setAll(all);
return this;
}
}
39 changes: 39 additions & 0 deletions src/main/java/net/sf/jsqlparser/statement/select/IntersectOp.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,46 @@

public class IntersectOp extends SetOperation {

private boolean distinct;
private boolean all;

public IntersectOp() {
super(SetOperationType.INTERSECT);
}
public boolean isAll() {
return all;
}

public void setAll(boolean all) {
this.all = all;
}

public boolean isDistinct() {
return distinct;
}

public void setDistinct(boolean distinct) {
this.distinct = distinct;
}

@Override
public String toString() {
String allDistinct = "";
if (isAll()) {
allDistinct = " ALL";
} else if (isDistinct()) {
allDistinct = " DISTINCT";
}
return super.toString() + allDistinct;
}

public IntersectOp withDistinct(boolean distinct) {
this.setDistinct(distinct);
return this;
}

public IntersectOp withAll(boolean all) {
this.setAll(all);
return this;
}
}
40 changes: 39 additions & 1 deletion src/main/java/net/sf/jsqlparser/statement/select/MinusOp.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,46 @@
import net.sf.jsqlparser.statement.select.SetOperationList.SetOperationType;

public class MinusOp extends SetOperation {

private boolean distinct;
private boolean all;

public MinusOp() {
super(SetOperationType.MINUS);
}
public boolean isAll() {
return all;
}

public void setAll(boolean all) {
this.all = all;
}

public boolean isDistinct() {
return distinct;
}

public void setDistinct(boolean distinct) {
this.distinct = distinct;
}

@Override
public String toString() {
String allDistinct = "";
if (isAll()) {
allDistinct = " ALL";
} else if (isDistinct()) {
allDistinct = " DISTINCT";
}
return super.toString() + allDistinct;
}

public MinusOp withDistinct(boolean distinct) {
this.setDistinct(distinct);
return this;
}

public MinusOp withAll(boolean all) {
this.setAll(all);
return this;
}
}
16 changes: 13 additions & 3 deletions src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -2612,11 +2612,21 @@ Select SetOperationList(Select select) #SetOperationList: {
[ <K_ALL> { union.setAll(true); } | <K_DISTINCT> { union.setDistinct(true); } ]
)
|
<K_INTERSECT> { operations.add(new IntersectOp()); }
(
<K_INTERSECT> { IntersectOp intersect = new IntersectOp(); linkAST(intersect,jjtThis); operations.add(intersect); }
[ <K_ALL> { intersect.setAll(true); } | <K_DISTINCT> { intersect.setDistinct(true); } ]
)
|
<K_MINUS> { operations.add(new MinusOp()); }
(
<K_MINUS> { MinusOp minus = new MinusOp(); linkAST(minus,jjtThis); operations.add(minus); }
[ <K_ALL> { minus.setAll(true); } | <K_DISTINCT> { minus.setDistinct(true); } ]
)
|
<K_EXCEPT> { operations.add(new ExceptOp()); }
(
<K_EXCEPT> { ExceptOp except = new ExceptOp(); linkAST(except,jjtThis); operations.add(except); }
[ <K_ALL> { except.setAll(true); } | <K_DISTINCT> { except.setDistinct(true); } ]
)

)

(
Expand Down
Loading