use of com.alibaba.druid.sql.ast.SQLParameter in project druid by alibaba.
the class MySqlStatementParser method parserParameters.
/**
* parse create procedure parameters
*
* @param parameters
*/
private void parserParameters(List<SQLParameter> parameters) {
if (lexer.token() == Token.RPAREN) {
return;
}
for (; ; ) {
SQLParameter parameter = new SQLParameter();
if (lexer.token() == Token.CURSOR) {
lexer.nextToken();
parameter.setName(this.exprParser.name());
accept(Token.IS);
SQLSelect select = this.createSQLSelectParser().select();
SQLDataTypeImpl dataType = new SQLDataTypeImpl();
dataType.setName("CURSOR");
parameter.setDataType(dataType);
parameter.setDefaultValue(new SQLQueryExpr(select));
} else if (lexer.token() == Token.IN || lexer.token() == Token.OUT || lexer.token() == Token.INOUT) {
if (lexer.token() == Token.IN) {
parameter.setParamType(ParameterType.IN);
} else if (lexer.token() == Token.OUT) {
parameter.setParamType(ParameterType.OUT);
} else if (lexer.token() == Token.INOUT) {
parameter.setParamType(ParameterType.INOUT);
}
lexer.nextToken();
parameter.setName(this.exprParser.name());
parameter.setDataType(this.exprParser.parseDataType());
} else {
// default parameter type is in
parameter.setParamType(ParameterType.DEFAULT);
parameter.setName(this.exprParser.name());
parameter.setDataType(this.exprParser.parseDataType());
if (lexer.token() == Token.COLONEQ) {
lexer.nextToken();
parameter.setDefaultValue(this.exprParser.expr());
}
}
parameters.add(parameter);
if (lexer.token() == Token.COMMA || lexer.token() == Token.SEMI) {
lexer.nextToken();
}
if (lexer.token() != Token.BEGIN && lexer.token() != Token.RPAREN) {
continue;
}
break;
}
}
use of com.alibaba.druid.sql.ast.SQLParameter in project druid by alibaba.
the class MySqlOutputVisitor method visit.
/**
* visit procedure create node
*/
@Override
public boolean visit(SQLCreateProcedureStatement x) {
if (x.isOrReplace()) {
print0(ucase ? "CREATE OR REPLACE PROCEDURE " : "create or replace procedure ");
} else {
print0(ucase ? "CREATE PROCEDURE " : "create procedure ");
}
x.getName().accept(this);
int paramSize = x.getParameters().size();
print0(" (");
if (paramSize > 0) {
incrementIndent();
println();
for (int i = 0; i < paramSize; ++i) {
if (i != 0) {
print0(", ");
println();
}
SQLParameter param = x.getParameters().get(i);
param.accept(this);
}
decrementIndent();
println();
}
print(')');
println();
x.getBlock().setParent(x);
x.getBlock().accept(this);
return false;
}
use of com.alibaba.druid.sql.ast.SQLParameter in project druid by alibaba.
the class OracleStatementParser method parseBlock.
public SQLBlockStatement parseBlock() {
SQLBlockStatement block = new SQLBlockStatement();
if (lexer.token() == Token.DECLARE) {
lexer.nextToken();
parserParameters(block.getParameters());
for (SQLParameter param : block.getParameters()) {
param.setParent(block);
}
}
accept(Token.BEGIN);
parseStatementList(block.getStatementList());
accept(Token.END);
return block;
}
use of com.alibaba.druid.sql.ast.SQLParameter in project druid by alibaba.
the class PGFunctionTableSource method clone.
@Override
public PGFunctionTableSource clone() {
PGFunctionTableSource x = new PGFunctionTableSource();
x.setAlias(this.alias);
for (SQLParameter e : this.parameters) {
SQLParameter e2 = e.clone();
e2.setParent(x);
x.getParameters().add(e2);
}
if (this.flashback != null) {
x.setFlashback(this.flashback.clone());
}
if (this.hints != null) {
for (SQLHint e : this.hints) {
SQLHint e2 = e.clone();
e2.setParent(x);
x.getHints().add(e2);
}
}
return x;
}
use of com.alibaba.druid.sql.ast.SQLParameter in project druid by alibaba.
the class OracleFunctionDataType method clone.
public OracleFunctionDataType clone() {
OracleFunctionDataType x = new OracleFunctionDataType();
cloneTo(x);
x.isStatic = isStatic;
if (returnDataType != null) {
x.setReturnDataType(returnDataType.clone());
}
for (SQLParameter parameter : parameters) {
SQLParameter p2 = parameter.clone();
p2.setParent(x);
x.parameters.add(p2);
}
return x;
}
Aggregations