support oracle connect_by_root

This commit is contained in:
Yako
2014-07-11 18:03:43 +08:00
parent 7e05e74165
commit bfc429b805
4 changed files with 83 additions and 1 deletions
@@ -23,6 +23,7 @@ public class SQLSelectItem extends SQLObjectImpl {
private SQLExpr expr;
private String alias;
private boolean connectByRoot = false;
public SQLSelectItem(){
@@ -40,6 +41,16 @@ public class SQLSelectItem extends SQLObjectImpl {
expr.setParent(this);
}
}
public SQLSelectItem(SQLExpr expr, String alias, boolean connectByRoot){
this.connectByRoot = connectByRoot;
this.expr = expr;
this.alias = alias;
if (expr != null) {
expr.setParent(this);
}
}
public SQLExpr getExpr() {
return this.expr;
@@ -61,6 +72,9 @@ public class SQLSelectItem extends SQLObjectImpl {
}
public void output(StringBuffer buf) {
if(this.connectByRoot) {
buf.append(" CONNECT_BY_ROOT ");
}
this.expr.output(buf);
if ((this.alias != null) && (this.alias.length() != 0)) {
buf.append(" AS ");
@@ -99,4 +113,12 @@ public class SQLSelectItem extends SQLObjectImpl {
return true;
}
public boolean isConnectByRoot() {
return connectByRoot;
}
public void setConnectByRoot(boolean connectByRoot) {
this.connectByRoot = connectByRoot;
}
}
@@ -284,7 +284,12 @@ public class SQLSelectParser extends SQLParser {
protected SQLSelectItem parseSelectItem() {
SQLExpr expr;
boolean connectByRoot = false;
if (lexer.token() == Token.IDENTIFIER) {
if (identifierEquals("CONNECT_BY_ROOT")) {
connectByRoot = true;
lexer.nextToken();
}
expr = new SQLIdentifierExpr(lexer.stringVal());
lexer.nextTokenComma();
@@ -297,7 +302,7 @@ public class SQLSelectParser extends SQLParser {
}
final String alias = as();
return new SQLSelectItem(expr, alias);
return new SQLSelectItem(expr, alias, connectByRoot);
}
public void parseFrom(SQLSelectQueryBlock queryBlock) {
@@ -697,6 +697,9 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
}
public boolean visit(SQLSelectItem x) {
if(x.isConnectByRoot()) {
print("CONNECT_BY_ROOT ");
}
x.getExpr().accept(this);
if ((x.getAlias() != null) && (x.getAlias().length() > 0)) {