Skip to content

Commit

Permalink
Fix issue of missing comma between joins in subjoin
Browse files Browse the repository at this point in the history
  • Loading branch information
tomershay committed Aug 5, 2019
1 parent d9025e8 commit 449c4e8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main/java/net/sf/jsqlparser/statement/select/Join.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public String toString() {
if (isSimple() && isOuter()) {
return "OUTER " + rightItem;
} else if (isSimple()) {
return "" + rightItem;
return ", " + rightItem;
} else {
String type = "";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("(").append(left);
for (Join j : joinList) {
sb.append(" ").append(j);
sb.append(j.isSimple() ? "" : " ").append(j);
}

sb.append(")").append((alias != null) ? (" " + alias.toString()) : "").append((pivot != null) ? " " + pivot : "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2009,6 +2009,12 @@ public void testWithStatement() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed(stmt);
}

@Test
public void testSubjoinWithJoins() throws JSQLParserException {
String stmt = "SELECT COUNT(DISTINCT `webProduct`.`id`) FROM (`webProduct`, `base`, `protectedBase`)";
assertSqlCanBeParsedAndDeparsed(stmt);
}

@Test
public void testWithUnionProblem() throws JSQLParserException {
String stmt = "WITH test AS ((SELECT mslink FROM tablea) UNION (SELECT mslink FROM tableb)) SELECT * FROM tablea WHERE mslink IN (SELECT mslink FROM test)";
Expand Down

0 comments on commit 449c4e8

Please sign in to comment.