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:
+20
-9
@@ -18,12 +18,7 @@ package com.alibaba.druid.sql.dialect.oracle.parser;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLDataTypeImpl;
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLHint;
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.ast.SQLParameter;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.ast.*;
|
||||
import com.alibaba.druid.sql.ast.expr.*;
|
||||
import com.alibaba.druid.sql.ast.statement.*;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.clause.OracleReturningClause;
|
||||
@@ -1062,8 +1057,10 @@ public class OracleStatementParser extends SQLStatementParser {
|
||||
|
||||
if (lexer.token() == Token.DECLARE) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
parserParameters(block.getParameters());
|
||||
if (lexer.token() == Token.IDENTIFIER) {
|
||||
parserParameters(block.getParameters(), block);
|
||||
for (SQLParameter param : block.getParameters()) {
|
||||
param.setParent(block);
|
||||
}
|
||||
@@ -1078,7 +1075,7 @@ public class OracleStatementParser extends SQLStatementParser {
|
||||
return block;
|
||||
}
|
||||
|
||||
private void parserParameters(List<SQLParameter> parameters) {
|
||||
private void parserParameters(List<SQLParameter> parameters, SQLObject parent) {
|
||||
for (;;) {
|
||||
SQLParameter parameter = new SQLParameter();
|
||||
|
||||
@@ -1591,7 +1588,7 @@ public class OracleStatementParser extends SQLStatementParser {
|
||||
|
||||
if (lexer.token() == Token.LPAREN) {
|
||||
lexer.nextToken();
|
||||
parserParameters(stmt.getParameters());
|
||||
parserParameters(stmt.getParameters(), stmt);
|
||||
accept(Token.RPAREN);
|
||||
}
|
||||
|
||||
@@ -1601,6 +1598,20 @@ public class OracleStatementParser extends SQLStatementParser {
|
||||
accept(Token.AS);
|
||||
}
|
||||
|
||||
if (identifierEquals("LANGUAGE")) {
|
||||
lexer.nextToken();
|
||||
if (identifierEquals("JAVA")) {
|
||||
lexer.nextToken();
|
||||
acceptIdentifier("NAME");
|
||||
String javaCallSpec = lexer.stringVal();
|
||||
accept(Token.LITERAL_CHARS);
|
||||
stmt.setJavaCallSpec(javaCallSpec);
|
||||
} else {
|
||||
throw new ParserException("TODO : " + lexer.info());
|
||||
}
|
||||
return stmt;
|
||||
}
|
||||
|
||||
SQLBlockStatement block = this.parseBlock();
|
||||
|
||||
stmt.setBlock(block);
|
||||
|
||||
+22
-4
@@ -1355,9 +1355,11 @@ public class OracleOutputVisitor extends SQLASTOutputVisitor implements OracleAS
|
||||
@Override
|
||||
public boolean visit(SQLBlockStatement x) {
|
||||
if (x.getParameters().size() != 0) {
|
||||
print0(ucase ? "DECLARE" : "declare");
|
||||
incrementIndent();
|
||||
println();
|
||||
if (!(x.getParent() instanceof SQLCreateProcedureStatement)) {
|
||||
print0(ucase ? "DECLARE" : "declare");
|
||||
println();
|
||||
}
|
||||
|
||||
for (int i = 0, size = x.getParameters().size(); i < size; ++i) {
|
||||
if (i != 0) {
|
||||
@@ -2542,14 +2544,30 @@ public class OracleOutputVisitor extends SQLASTOutputVisitor implements OracleAS
|
||||
print(')');
|
||||
}
|
||||
|
||||
SQLStatement block = x.getBlock();
|
||||
|
||||
if (!create) {
|
||||
println();
|
||||
println("IS");
|
||||
} else {
|
||||
println();
|
||||
if (block instanceof SQLBlockStatement) {
|
||||
SQLBlockStatement blockStatement = (SQLBlockStatement) block;
|
||||
if (blockStatement.getParameters().size() > 0) {
|
||||
println("AS");
|
||||
}
|
||||
}
|
||||
}
|
||||
x.getBlock().setParent(x);
|
||||
x.getBlock().accept(this);
|
||||
|
||||
String javaCallSpec = x.getJavaCallSpec();
|
||||
if (javaCallSpec != null) {
|
||||
print0(ucase ? "LANGUAGE JAVA NAME '" : "language java name '");
|
||||
print0(javaCallSpec);
|
||||
print('\'');
|
||||
return false;
|
||||
}
|
||||
|
||||
block.accept(this);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user