Search in sources :

Example 21 with SQLSelect

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

the class SQLSelectBuilderImpl method getQueryBlock.

protected SQLSelectQueryBlock getQueryBlock() {
    SQLSelect select = getSQLSelect();
    SQLSelectQuery query = select.getQuery();
    if (query == null) {
        query = createSelectQueryBlock();
        select.setQuery(query);
    }
    if (!(query instanceof SQLSelectQueryBlock)) {
        throw new IllegalStateException("not support from, class : " + query.getClass().getName());
    }
    SQLSelectQueryBlock queryBlock = (SQLSelectQueryBlock) query;
    return queryBlock;
}
Also used : SQLSelect(com.alibaba.druid.sql.ast.statement.SQLSelect) SQLSelectQuery(com.alibaba.druid.sql.ast.statement.SQLSelectQuery) SQLSelectQueryBlock(com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock)

Example 22 with SQLSelect

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

the class SQLSelectBuilderImpl method orderBy.

@Override
public SQLSelectBuilderImpl orderBy(String... columns) {
    SQLSelect select = this.getSQLSelect();
    SQLOrderBy orderBy = select.getOrderBy();
    if (orderBy == null) {
        orderBy = createOrderBy();
        select.setOrderBy(orderBy);
    }
    for (String column : columns) {
        SQLSelectOrderByItem orderByItem = SQLUtils.toOrderByItem(column, dbType);
        orderBy.addItem(orderByItem);
    }
    return this;
}
Also used : SQLOrderBy(com.alibaba.druid.sql.ast.SQLOrderBy) SQLSelect(com.alibaba.druid.sql.ast.statement.SQLSelect) SQLSelectOrderByItem(com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem)

Example 23 with SQLSelect

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

the class PGSQLStatementParser method parseSelect.

public PGSelectStatement parseSelect() {
    PGSelectParser selectParser = createSQLSelectParser();
    SQLSelect select = selectParser.select();
    return new PGSelectStatement(select);
}
Also used : PGSelectStatement(com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectStatement) SQLSelect(com.alibaba.druid.sql.ast.statement.SQLSelect)

Example 24 with SQLSelect

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

the class SQLExprParser method parseAll.

protected SQLExpr parseAll() {
    SQLExpr sqlExpr;
    lexer.nextToken();
    SQLAllExpr allExpr = new SQLAllExpr();
    accept(Token.LPAREN);
    SQLSelect allSubQuery = createSelectParser().select();
    allExpr.setSubQuery(allSubQuery);
    accept(Token.RPAREN);
    allSubQuery.setParent(allExpr);
    sqlExpr = allExpr;
    return sqlExpr;
}
Also used : SQLSelect(com.alibaba.druid.sql.ast.statement.SQLSelect)

Example 25 with SQLSelect

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

the class SQLExprParser method parseSome.

protected SQLExpr parseSome() {
    SQLExpr sqlExpr;
    lexer.nextToken();
    SQLSomeExpr someExpr = new SQLSomeExpr();
    accept(Token.LPAREN);
    SQLSelect someSubQuery = createSelectParser().select();
    someExpr.setSubQuery(someSubQuery);
    accept(Token.RPAREN);
    someSubQuery.setParent(someExpr);
    sqlExpr = someExpr;
    return sqlExpr;
}
Also used : SQLSelect(com.alibaba.druid.sql.ast.statement.SQLSelect)

Aggregations

SQLSelect (com.alibaba.druid.sql.ast.statement.SQLSelect)40 SQLSelectStatement (com.alibaba.druid.sql.ast.statement.SQLSelectStatement)21 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)19 MySqlStatementParser (com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser)16 MySqlSelectQueryBlock (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock)15 MySqlSchemaStatVisitor (com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor)15 SQLSelectQueryBlock (com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock)8 SQLSubqueryTableSource (com.alibaba.druid.sql.ast.statement.SQLSubqueryTableSource)7 SQLBinaryOpExpr (com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr)6 SQLSelectQuery (com.alibaba.druid.sql.ast.statement.SQLSelectQuery)6 SQLSelectItem (com.alibaba.druid.sql.ast.statement.SQLSelectItem)5 SQLIdentifierExpr (com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr)4 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)3 SQLName (com.alibaba.druid.sql.ast.SQLName)3 SQLOrderBy (com.alibaba.druid.sql.ast.SQLOrderBy)3 SQLAllColumnExpr (com.alibaba.druid.sql.ast.expr.SQLAllColumnExpr)3 SQLNumberExpr (com.alibaba.druid.sql.ast.expr.SQLNumberExpr)3 SQLPropertyExpr (com.alibaba.druid.sql.ast.expr.SQLPropertyExpr)3 SQLTableSource (com.alibaba.druid.sql.ast.statement.SQLTableSource)3 SQLServerSelectQueryBlock (com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerSelectQueryBlock)3