Search in sources :

Example 1 with SQLParameter

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;
    }
}
Also used : SQLQueryExpr(com.alibaba.druid.sql.ast.expr.SQLQueryExpr) SQLParameter(com.alibaba.druid.sql.ast.SQLParameter) SQLDataTypeImpl(com.alibaba.druid.sql.ast.SQLDataTypeImpl)

Example 2 with SQLParameter

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;
}
Also used : SQLParameter(com.alibaba.druid.sql.ast.SQLParameter) MySqlForceIndexHint(com.alibaba.druid.sql.dialect.mysql.ast.MySqlForceIndexHint) SQLCommentHint(com.alibaba.druid.sql.ast.SQLCommentHint) MySqlUseIndexHint(com.alibaba.druid.sql.dialect.mysql.ast.MySqlUseIndexHint) MySqlIgnoreIndexHint(com.alibaba.druid.sql.dialect.mysql.ast.MySqlIgnoreIndexHint)

Example 3 with SQLParameter

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;
}
Also used : SQLParameter(com.alibaba.druid.sql.ast.SQLParameter)

Example 4 with SQLParameter

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;
}
Also used : SQLParameter(com.alibaba.druid.sql.ast.SQLParameter) SQLHint(com.alibaba.druid.sql.ast.SQLHint)

Example 5 with SQLParameter

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;
}
Also used : SQLParameter(com.alibaba.druid.sql.ast.SQLParameter)

Aggregations

SQLParameter (com.alibaba.druid.sql.ast.SQLParameter)11 SQLDataTypeImpl (com.alibaba.druid.sql.ast.SQLDataTypeImpl)2 SQLQueryExpr (com.alibaba.druid.sql.ast.expr.SQLQueryExpr)2 SQLCommentHint (com.alibaba.druid.sql.ast.SQLCommentHint)1 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)1 SQLHint (com.alibaba.druid.sql.ast.SQLHint)1 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)1 MergeInsertClause (com.alibaba.druid.sql.ast.statement.SQLMergeStatement.MergeInsertClause)1 MergeUpdateClause (com.alibaba.druid.sql.ast.statement.SQLMergeStatement.MergeUpdateClause)1 MySqlForceIndexHint (com.alibaba.druid.sql.dialect.mysql.ast.MySqlForceIndexHint)1 MySqlIgnoreIndexHint (com.alibaba.druid.sql.dialect.mysql.ast.MySqlIgnoreIndexHint)1 MySqlUseIndexHint (com.alibaba.druid.sql.dialect.mysql.ast.MySqlUseIndexHint)1 OracleDataTypeIntervalDay (com.alibaba.druid.sql.dialect.oracle.ast.OracleDataTypeIntervalDay)1 OracleDataTypeIntervalYear (com.alibaba.druid.sql.dialect.oracle.ast.OracleDataTypeIntervalYear)1 ModelClause (com.alibaba.druid.sql.dialect.oracle.ast.clause.ModelClause)1 ConditionalInsertClause (com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleMultiInsertStatement.ConditionalInsertClause)1 ConditionalInsertClauseItem (com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleMultiInsertStatement.ConditionalInsertClauseItem)1 InsertIntoClause (com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleMultiInsertStatement.InsertIntoClause)1 CheckOption (com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleSelectRestriction.CheckOption)1 ReadOnly (com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleSelectRestriction.ReadOnly)1