Search in sources :

Example 21 with SQLAllColumnExpr

use of com.alibaba.druid.sql.ast.expr.SQLAllColumnExpr in project druid by alibaba.

the class Resolve_AllColumn_Test method test_resolve.

public void test_resolve() throws Exception {
    SchemaRepository repository = new SchemaRepository(DbType.mysql);
    repository.acceptDDL("create table t_emp(emp_id bigint, name varchar(20));");
    SQLStatement stmt = SQLUtils.parseSingleMysqlStatement("select * from t_emp");
    repository.resolve(stmt, SchemaResolveVisitor.Option.ResolveAllColumn);
    assertEquals("SELECT emp_id, name\n" + "FROM t_emp", stmt.toString());
    SQLSelectQueryBlock queryBlock = ((SQLSelectStatement) stmt).getSelect().getQueryBlock();
    SQLIdentifierExpr expr = (SQLIdentifierExpr) queryBlock.getSelectList().get(0).getExpr();
    assertNotNull(expr.getResolvedColumn());
    new SQLASTVisitorAdapter() {

        public boolean visit(SQLSelectQueryBlock queryBlock) {
            final List<SQLSelectItem> selectList = queryBlock.getSelectList();
            for (int i = 0; i < selectList.size(); i++) {
                final SQLSelectItem selectItem = selectList.get(i);
                final SQLExpr expr = selectItem.getExpr();
                if (expr instanceof SQLAllColumnExpr) {
                } else if (expr instanceof SQLPropertyExpr && ((SQLPropertyExpr) expr).getName().equals("*")) {
                }
            }
            return true;
        }
    };
}
Also used : SQLASTVisitorAdapter(com.alibaba.druid.sql.visitor.SQLASTVisitorAdapter) SQLSelectItem(com.alibaba.druid.sql.ast.statement.SQLSelectItem) SQLAllColumnExpr(com.alibaba.druid.sql.ast.expr.SQLAllColumnExpr) SQLSelectQueryBlock(com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock) SQLIdentifierExpr(com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr) SQLPropertyExpr(com.alibaba.druid.sql.ast.expr.SQLPropertyExpr) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr) SchemaRepository(com.alibaba.druid.sql.repository.SchemaRepository)

Aggregations

SQLAllColumnExpr (com.alibaba.druid.sql.ast.expr.SQLAllColumnExpr)21 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)13 SQLSelectItem (com.alibaba.druid.sql.ast.statement.SQLSelectItem)10 SQLIdentifierExpr (com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr)9 SQLPropertyExpr (com.alibaba.druid.sql.ast.expr.SQLPropertyExpr)9 SQLAggregateExpr (com.alibaba.druid.sql.ast.expr.SQLAggregateExpr)8 SQLSelectQueryBlock (com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock)5 SQLDataType (com.alibaba.druid.sql.ast.SQLDataType)4 SQLSelect (com.alibaba.druid.sql.ast.statement.SQLSelect)4 SQLDataTypeImpl (com.alibaba.druid.sql.ast.SQLDataTypeImpl)3 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)3 SQLBinaryOpExpr (com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr)3 SQLIntegerExpr (com.alibaba.druid.sql.ast.expr.SQLIntegerExpr)3 SQLNumberExpr (com.alibaba.druid.sql.ast.expr.SQLNumberExpr)3 SQLNumericLiteralExpr (com.alibaba.druid.sql.ast.expr.SQLNumericLiteralExpr)3 SQLVariantRefExpr (com.alibaba.druid.sql.ast.expr.SQLVariantRefExpr)3 SQLCharacterDataType (com.alibaba.druid.sql.ast.statement.SQLCharacterDataType)3 SQLSelectQuery (com.alibaba.druid.sql.ast.statement.SQLSelectQuery)3 SQLSubqueryTableSource (com.alibaba.druid.sql.ast.statement.SQLSubqueryTableSource)3 DB2SelectQueryBlock (com.alibaba.druid.sql.dialect.db2.ast.stmt.DB2SelectQueryBlock)3