Skip to content

Commit

Permalink
added possibility to query correlated outer tables in select statements
Browse files Browse the repository at this point in the history
  • Loading branch information
clausnagel committed Feb 7, 2020
1 parent 5bbebda commit 3c3c8bc
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
23 changes: 23 additions & 0 deletions src/main/java/org/citydb/sqlbuilder/select/Select.java
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,29 @@ public Set<Table> getInvolvedTables() {
return tables;
}

public Set<Table> getOuterTables() {
Set<Table> tables = new LinkedHashSet<>();

for (PredicateToken token : predicateTokens)
token.getInvolvedTables(tables);

for (HavingToken token : havingTokens)
token.getInvolvedTables(tables);

for (OrderByToken token : orderByTokens)
token.getInvolvedTables(tables);

if (offsetToken != null)
offsetToken.getInvolvedTables(tables);

if (fetchToken != null)
fetchToken.getInvolvedTables(tables);

tables.removeAll(getInvolvedTables());

return tables;
}

@Override
public List<PlaceHolder<?>> getInvolvedPlaceHolders() {
List<PlaceHolder<?>> statements = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.citydb.sqlbuilder.schema.Table;
import org.citydb.sqlbuilder.select.PredicateToken;
import org.citydb.sqlbuilder.select.ProjectionToken;
import org.citydb.sqlbuilder.select.Select;
import org.citydb.sqlbuilder.select.operator.Operator;

import java.util.List;
Expand All @@ -37,6 +38,8 @@ public void getInvolvedTables(Expression operand, Set<Table> tables) {
((ProjectionToken) operand).getInvolvedTables(tables);
else if (operand instanceof PredicateToken)
((PredicateToken) operand).getInvolvedTables(tables);
else if (operand instanceof Select)
tables.addAll(((Select) operand).getOuterTables());
}

public void getInvolvedPlaceHolders(Expression operand, List<PlaceHolder<?>> statements) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public String getAsName() {

@Override
public void getInvolvedTables(Set<Table> tables) {
// nothing to do here
tables.addAll(select.getOuterTables());
}

@Override
Expand Down

0 comments on commit 3c3c8bc

Please sign in to comment.