Search in sources :

Example 1 with SQLCallStatement

use of com.alibaba.druid.sql.ast.statement.SQLCallStatement in project dble by actiontech.

the class AbstractRouteStrategy method parseProcedureForCall.

private void parseProcedureForCall(Procedure procedure, String query, SQLCallStatement statement) {
    SQLCallStatement sqlCallStatement = statement;
    procedure.setName(sqlCallStatement.getProcedureName().getSimpleName());
    List<SQLExpr> parameterList = sqlCallStatement.getParameters();
    for (int i1 = 0; i1 < parameterList.size(); i1++) {
        SQLExpr sqlExpr = parameterList.get(i1);
        String pName = sqlExpr.toString();
        ProcedureParameter parameter = new ProcedureParameter();
        parameter.setIndex(i1 + 1);
        parameter.setName(pName);
        parameter.setParameterType(ProcedureParameter.IN);
        if (pName.startsWith("@")) {
            procedure.getParameterMap().put(pName, parameter);
        } else {
            procedure.getParameterMap().put(String.valueOf(i1 + 1), parameter);
        }
    }
    procedure.setCallSql(query);
}
Also used : ProcedureParameter(com.actiontech.dble.route.ProcedureParameter) SQLCallStatement(com.alibaba.druid.sql.ast.statement.SQLCallStatement) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr)

Example 2 with SQLCallStatement

use of com.alibaba.druid.sql.ast.statement.SQLCallStatement in project dble by actiontech.

the class AbstractRouteStrategy method parseProcedure.

private Procedure parseProcedure(String sql) {
    Procedure procedure = new Procedure();
    procedure.setOriginSql(sql);
    procedure.setResultList(false);
    SQLStatementParser parser = new MySqlStatementParser(sql);
    SQLStatement statement = parser.parseStatement();
    if (statement instanceof SQLCallStatement) {
        parseProcedureForCall(procedure, sql, (SQLCallStatement) statement);
    }
    return procedure;
}
Also used : SQLStatementParser(com.alibaba.druid.sql.parser.SQLStatementParser) Procedure(com.actiontech.dble.route.Procedure) SQLCallStatement(com.alibaba.druid.sql.ast.statement.SQLCallStatement) MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Example 3 with SQLCallStatement

use of com.alibaba.druid.sql.ast.statement.SQLCallStatement in project druid by alibaba.

the class SQLASTVisitorAdapterTest method test_adapter.

public void test_adapter() throws Exception {
    SQLASTVisitorAdapter adapter = new SQLASTVisitorAdapter();
    new SQLBinaryOpExpr().accept(adapter);
    new SQLInListExpr().accept(adapter);
    new SQLSelectQueryBlock().accept(adapter);
    new SQLDropTableStatement().accept(adapter);
    new SQLCreateTableStatement().accept(adapter);
    new SQLDeleteStatement().accept(adapter);
    new SQLCurrentOfCursorExpr().accept(adapter);
    new SQLInsertStatement().accept(adapter);
    new SQLUpdateStatement().accept(adapter);
    new SQLNotNullConstraint().accept(adapter);
    new SQLMethodInvokeExpr().accept(adapter);
    new SQLCallStatement().accept(adapter);
    new SQLSomeExpr().accept(adapter);
    new SQLAnyExpr().accept(adapter);
    new SQLAllExpr().accept(adapter);
    new SQLDefaultExpr().accept(adapter);
    new SQLCommentStatement().accept(adapter);
    new SQLDropViewStatement().accept(adapter);
    new SQLSavePointStatement().accept(adapter);
    new SQLReleaseSavePointStatement().accept(adapter);
    new SQLCreateDatabaseStatement().accept(adapter);
    new SQLAlterTableDropIndex().accept(adapter);
    new SQLOver().accept(adapter);
    new SQLWithSubqueryClause().accept(adapter);
    new SQLAlterTableAlterColumn().accept(adapter);
    new SQLAlterTableStatement().accept(adapter);
    new SQLAlterTableDisableConstraint().accept(adapter);
    new SQLAlterTableEnableConstraint().accept(adapter);
    new SQLColumnCheck().accept(adapter);
    new SQLExprHint().accept(adapter);
    new SQLAlterTableDropConstraint().accept(adapter);
}
Also used : SQLASTVisitorAdapter(com.alibaba.druid.sql.visitor.SQLASTVisitorAdapter) SQLCreateTableStatement(com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement) SQLMethodInvokeExpr(com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr) SQLAlterTableDropIndex(com.alibaba.druid.sql.ast.statement.SQLAlterTableDropIndex) SQLAlterTableStatement(com.alibaba.druid.sql.ast.statement.SQLAlterTableStatement) SQLAllExpr(com.alibaba.druid.sql.ast.expr.SQLAllExpr) SQLReleaseSavePointStatement(com.alibaba.druid.sql.ast.statement.SQLReleaseSavePointStatement) SQLNotNullConstraint(com.alibaba.druid.sql.ast.statement.SQLNotNullConstraint) SQLOver(com.alibaba.druid.sql.ast.SQLOver) SQLDropTableStatement(com.alibaba.druid.sql.ast.statement.SQLDropTableStatement) SQLCreateDatabaseStatement(com.alibaba.druid.sql.ast.statement.SQLCreateDatabaseStatement) SQLDropViewStatement(com.alibaba.druid.sql.ast.statement.SQLDropViewStatement) SQLInsertStatement(com.alibaba.druid.sql.ast.statement.SQLInsertStatement) SQLBinaryOpExpr(com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr) SQLAlterTableDisableConstraint(com.alibaba.druid.sql.ast.statement.SQLAlterTableDisableConstraint) SQLSavePointStatement(com.alibaba.druid.sql.ast.statement.SQLSavePointStatement) SQLAlterTableDropConstraint(com.alibaba.druid.sql.ast.statement.SQLAlterTableDropConstraint) SQLUpdateStatement(com.alibaba.druid.sql.ast.statement.SQLUpdateStatement) SQLCallStatement(com.alibaba.druid.sql.ast.statement.SQLCallStatement) SQLSomeExpr(com.alibaba.druid.sql.ast.expr.SQLSomeExpr) SQLInListExpr(com.alibaba.druid.sql.ast.expr.SQLInListExpr) SQLExprHint(com.alibaba.druid.sql.ast.statement.SQLExprHint) SQLWithSubqueryClause(com.alibaba.druid.sql.ast.statement.SQLWithSubqueryClause) SQLDeleteStatement(com.alibaba.druid.sql.ast.statement.SQLDeleteStatement) SQLCurrentOfCursorExpr(com.alibaba.druid.sql.ast.expr.SQLCurrentOfCursorExpr) SQLCommentStatement(com.alibaba.druid.sql.ast.statement.SQLCommentStatement) SQLColumnCheck(com.alibaba.druid.sql.ast.statement.SQLColumnCheck) SQLAnyExpr(com.alibaba.druid.sql.ast.expr.SQLAnyExpr) SQLAlterTableAlterColumn(com.alibaba.druid.sql.ast.statement.SQLAlterTableAlterColumn) SQLSelectQueryBlock(com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock) SQLDefaultExpr(com.alibaba.druid.sql.ast.expr.SQLDefaultExpr) SQLAlterTableEnableConstraint(com.alibaba.druid.sql.ast.statement.SQLAlterTableEnableConstraint)

Aggregations

SQLCallStatement (com.alibaba.druid.sql.ast.statement.SQLCallStatement)3 Procedure (com.actiontech.dble.route.Procedure)1 ProcedureParameter (com.actiontech.dble.route.ProcedureParameter)1 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)1 SQLOver (com.alibaba.druid.sql.ast.SQLOver)1 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)1 SQLAllExpr (com.alibaba.druid.sql.ast.expr.SQLAllExpr)1 SQLAnyExpr (com.alibaba.druid.sql.ast.expr.SQLAnyExpr)1 SQLBinaryOpExpr (com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr)1 SQLCurrentOfCursorExpr (com.alibaba.druid.sql.ast.expr.SQLCurrentOfCursorExpr)1 SQLDefaultExpr (com.alibaba.druid.sql.ast.expr.SQLDefaultExpr)1 SQLInListExpr (com.alibaba.druid.sql.ast.expr.SQLInListExpr)1 SQLMethodInvokeExpr (com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr)1 SQLSomeExpr (com.alibaba.druid.sql.ast.expr.SQLSomeExpr)1 SQLAlterTableAlterColumn (com.alibaba.druid.sql.ast.statement.SQLAlterTableAlterColumn)1 SQLAlterTableDisableConstraint (com.alibaba.druid.sql.ast.statement.SQLAlterTableDisableConstraint)1 SQLAlterTableDropConstraint (com.alibaba.druid.sql.ast.statement.SQLAlterTableDropConstraint)1 SQLAlterTableDropIndex (com.alibaba.druid.sql.ast.statement.SQLAlterTableDropIndex)1 SQLAlterTableEnableConstraint (com.alibaba.druid.sql.ast.statement.SQLAlterTableEnableConstraint)1 SQLAlterTableStatement (com.alibaba.druid.sql.ast.statement.SQLAlterTableStatement)1