Package com.alibaba.druid.sql.visitor

Examples of com.alibaba.druid.sql.visitor.SQLEvalVisitor


        SQLStatement sqlStmt = stmtList.get(0);
        if (sqlStmt instanceof SQLSelectStatement) {
            SQLSelectStatement selectStmt = (SQLSelectStatement) sqlStmt;

            SQLEvalVisitor evalVisitor = SQLEvalVisitorUtils.createEvalVisitor(dbType);
            selectStmt.accept(evalVisitor);

            SQLSelectQueryBlock selectQueryBlock = (SQLSelectQueryBlock) selectStmt.getSelect().getQuery();

            SQLExprTableSource tableSource = (SQLExprTableSource) selectQueryBlock.getFrom();
            String tableName = ((SQLIdentifierExpr) tableSource.getExpr()).getName();

            SingleTableQueryExecutePlan singleTableQueryExecuetePlan = new SingleTableQueryExecutePlan();
            singleTableQueryExecuetePlan.setMapping(mapping);
            singleTableQueryExecuetePlan.setTableName(tableName);

            splitCondition(singleTableQueryExecuetePlan.getConditions(), selectQueryBlock.getWhere());

            HResultSetMetaDataImpl resultMetaData = new HResultSetMetaDataImpl();
            for (SQLSelectItem selectItem : selectQueryBlock.getSelectList()) {
                ColumnMetaData columnMetaData = new ColumnMetaData();
                if (selectItem.getAlias() != null) {
                    columnMetaData.setColumnLabel(selectItem.getAlias());
                }
                columnMetaData.setColumnName(SQLUtils.toSQLString(selectItem.getExpr(), dbType));
                columnMetaData.setColumnType(Types.BINARY);
                resultMetaData.getColumns().add(columnMetaData);
            }
            singleTableQueryExecuetePlan.setResultMetaData(resultMetaData);

            this.executePlan = singleTableQueryExecuetePlan;
        } else if (sqlStmt instanceof SQLInsertStatement) {
            SQLInsertStatement insertStmt = (SQLInsertStatement) sqlStmt;

            SQLEvalVisitor evalVisitor = SQLEvalVisitorUtils.createEvalVisitor(dbType);
            insertStmt.accept(evalVisitor);

            String tableName = ((SQLIdentifierExpr) insertStmt.getTableSource().getExpr()).getName();

            InsertExecutePlan insertExecutePlan = new InsertExecutePlan();
View Full Code Here


        return null;
    }

    public static Object eval(WallVisitor wallVisitor, String dbType, SQLObject sqlObject, List<Object> parameters) {
        SQLEvalVisitor visitor = SQLEvalVisitorUtils.createEvalVisitor(dbType);
        visitor.setParameters(parameters);
        visitor.registerFunction("rand", Nil.instance);
        sqlObject.accept(visitor);

        if (sqlObject instanceof SQLNumericLiteralExpr) {
            return ((SQLNumericLiteralExpr) sqlObject).getNumber();
        }
View Full Code Here

TOP

Related Classes of com.alibaba.druid.sql.visitor.SQLEvalVisitor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.