improved PageUtils & support natural join. issue #1711

This commit is contained in:
wenshao
2017-05-08 03:27:32 +08:00
parent 2dbe1da578
commit 306f956273
8 changed files with 221 additions and 1 deletions
@@ -572,8 +572,14 @@ public class PagerUtils {
if (parent instanceof SQLSelectQuery) {
if (parent instanceof OracleSelectQueryBlock) {
OracleSelectQueryBlock queryBlock = (OracleSelectQueryBlock) parent;
if (queryBlock.getFrom() instanceof SQLExprTableSource) {
SQLTableSource from = queryBlock.getFrom();
if (from instanceof SQLExprTableSource) {
selectQuery = queryBlock;
} else if (from instanceof SQLSubqueryTableSource) {
SQLSelect subSelect = ((SQLSubqueryTableSource) from).getSelect();
if (subSelect.getQuery() instanceof OracleSelectQueryBlock) {
selectQuery = (OracleSelectQueryBlock) subSelect.getQuery();
}
}
}
break;
@@ -581,6 +587,7 @@ public class PagerUtils {
}
}
if (selectQuery != null) {
SQLObject parent = selectQuery.getParent();
if (parent instanceof SQLSelect) {
@@ -29,6 +29,9 @@ public class SQLJoinTableSource extends SQLTableSourceImpl {
protected SQLExpr condition;
protected final List<SQLExpr> using = new ArrayList<SQLExpr>();
protected boolean natural = false;
public SQLJoinTableSource(String alias){
super(alias);
}
@@ -93,6 +96,14 @@ public class SQLJoinTableSource extends SQLTableSourceImpl {
return this.using;
}
public boolean isNatural() {
return natural;
}
public void setNatural(boolean natural) {
this.natural = natural;
}
public void output(StringBuffer buf) {
this.left.output(buf);
buf.append(' ');
@@ -458,6 +458,12 @@ public class SQLSelectParser extends SQLParser {
SQLJoinTableSource.JoinType joinType = null;
boolean natural = false;
if (JdbcConstants.MYSQL.equals(dbType) && identifierEquals("NATURAL")) {
lexer.nextToken();
natural = true;
}
if (lexer.token() == Token.LEFT) {
lexer.nextToken();
if (lexer.token() == Token.OUTER) {
@@ -516,6 +522,14 @@ public class SQLSelectParser extends SQLParser {
join.setJoinType(joinType);
join.setRight(parseTableSource());
if (!natural) {
if (JdbcConstants.MYSQL.equals(dbType) && "NATURAL".equalsIgnoreCase(tableSource.getAlias())) {
tableSource.setAlias(null);
natural = true;
}
}
join.setNatural(natural);
if (lexer.token() == Token.ON) {
lexer.nextToken();
join.setCondition(expr());
@@ -1856,6 +1856,11 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
print(',');
} else {
println();
if (x.isNatural()) {
print0(ucase ? "NATURAL " : "natural ");
}
printJoinType(x.getJoinType());
}
print(' ');