readIf("OUTER");
read("JOIN");
// the right hand side is the 'inner' table usually
TableFilter newTop = readTableFilter(fromOuter);
newTop = readJoin(newTop, command, true);
Expression on = null;
if (readIf("ON")) {
on = readExpression();
}
newTop.addJoin(top, true, on);
top = newTop;
last = newTop;
} else if (readIf("LEFT")) {
readIf("OUTER");
read("JOIN");
TableFilter join = readTableFilter(true);
top = readJoin(top, command, true);
Expression on = null;
if (readIf("ON")) {
on = readExpression();
}
top.addJoin(join, true, on);
last = join;
} else if (readIf("FULL")) {
throw this.getSyntaxError();
} else if (readIf("INNER")) {
read("JOIN");
TableFilter join = readTableFilter(fromOuter);
top = readJoin(top, command, false);
Expression on = null;
if (readIf("ON")) {
on = readExpression();
}
top.addJoin(join, fromOuter, on);
last = join;
} else if (readIf("JOIN")) {
TableFilter join = readTableFilter(fromOuter);
top = readJoin(top, command, false);
Expression on = null;
if (readIf("ON")) {
on = readExpression();
}
top.addJoin(join, fromOuter, on);
last = join;
} else if (readIf("CROSS")) {
read("JOIN");
TableFilter join = readTableFilter(fromOuter);
top.addJoin(join, fromOuter, null);
last = join;
} else if (readIf("NATURAL")) {
read("JOIN");
TableFilter join = readTableFilter(fromOuter);
Column[] tableCols = last.getTable().getColumns().toArray(new Column[0]);
Column[] joinCols = join.getTable().getColumns().toArray(new Column[0]);
String tableSchema = last.getTable().getSchema().getName();
String joinSchema = join.getTable().getSchema().getName();
Expression on = null;
for (Column tc : tableCols) {
String tableColumnName = tc.getName();
for (Column c : joinCols) {
String joinColumnName = c.getName();
if (tableColumnName.equals(joinColumnName)) {
// XXX join.addNaturalJoinColumn(c);
Expression tableExpr = new ExpressionColumn(session, tableSchema, last
.getTableAlias(), tableColumnName);
Expression joinExpr = new ExpressionColumn(session, joinSchema, join
.getTableAlias(), joinColumnName);
Expression equal = new Comparison(session, Operator.EQUAL, tableExpr, joinExpr);
if (on == null) {
on = equal;
} else {
on = new ConditionAndOr(session, ConditionAndOr.AND, on, equal);
}