mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved oracle pl/sql parser.
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.alibaba.druid.sql.ast.statement;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLStatementImpl;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
/**
|
||||
@@ -24,7 +25,9 @@ import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
public class SQLOpenStatement extends SQLStatementImpl{
|
||||
|
||||
//cursor name
|
||||
private String cursorName;
|
||||
private String cursorName;
|
||||
|
||||
private SQLExpr forExpr;
|
||||
|
||||
public String getCursorName() {
|
||||
return cursorName;
|
||||
@@ -36,10 +39,20 @@ public class SQLOpenStatement extends SQLStatementImpl{
|
||||
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
// TODO Auto-generated method stub
|
||||
visitor.visit(this);
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, forExpr);
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
|
||||
}
|
||||
|
||||
public SQLExpr getFor() {
|
||||
return forExpr;
|
||||
}
|
||||
|
||||
public void setFor(SQLExpr forExpr) {
|
||||
if (forExpr != null) {
|
||||
forExpr.setParent(this);
|
||||
}
|
||||
this.forExpr = forExpr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -422,6 +422,12 @@ public class OracleStatementParser extends SQLStatementParser {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.CLOSE) {
|
||||
SQLStatement stmt = this.parseClose();
|
||||
statementList.add(stmt);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.CASE) {
|
||||
SQLStatement stmt = this.parseCase();
|
||||
statementList.add(stmt);
|
||||
|
||||
@@ -26,6 +26,7 @@ import com.alibaba.druid.sql.ast.SQLObject;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLCharExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLQueryExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLVariantRefExpr;
|
||||
import com.alibaba.druid.sql.ast.statement.*;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCreateTriggerStatement.TriggerEvent;
|
||||
@@ -2189,6 +2190,18 @@ public class SQLStatementParser extends SQLParser {
|
||||
SQLOpenStatement stmt = new SQLOpenStatement();
|
||||
accept(Token.OPEN);
|
||||
stmt.setCursorName(exprParser.name().getSimpleName());
|
||||
|
||||
if (lexer.token() == Token.FOR) {
|
||||
lexer.nextToken();
|
||||
if (lexer.token() == Token.SELECT) {
|
||||
SQLSelectParser selectParser = createSQLSelectParser();
|
||||
SQLSelect select = selectParser.select();
|
||||
SQLQueryExpr queryExpr = new SQLQueryExpr(select);
|
||||
stmt.setFor(queryExpr);
|
||||
} else {
|
||||
throw new ParserException("TODO " + lexer.info());
|
||||
}
|
||||
}
|
||||
accept(Token.SEMI);
|
||||
return stmt;
|
||||
}
|
||||
|
||||
@@ -1025,6 +1025,8 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
x.getSubQuery().accept(this);
|
||||
print(')');
|
||||
println();
|
||||
} else if (parent instanceof SQLOpenStatement) {
|
||||
x.getSubQuery().accept(this);
|
||||
} else {
|
||||
print('(');
|
||||
incrementIndent();
|
||||
@@ -3201,6 +3203,12 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
public boolean visit(SQLOpenStatement x) {
|
||||
print0(ucase ? "OPEN " : "open ");
|
||||
print0(x.getCursorName());
|
||||
|
||||
SQLExpr forExpr = x.getFor();
|
||||
if (forExpr != null) {
|
||||
print0(ucase ? " FOR " : "for ");
|
||||
forExpr.accept(this);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user