Skip to content

Commit

Permalink
added support for minus all; except all; intersect all;
Browse files Browse the repository at this point in the history
  • Loading branch information
sunanda-vs committed Sep 20, 2024
1 parent 5cf281f commit 9a62bc0
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 4 deletions.
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

0 comments on commit 9a62bc0

Please sign in to comment.