Search in sources :

Example 46 with SQLExpr

use of com.alibaba.druid.sql.ast.SQLExpr in project druid by alibaba.

the class MySqlExprParser method parseAggregateExprRest.

protected SQLAggregateExpr parseAggregateExprRest(SQLAggregateExpr aggregateExpr) {
    if (lexer.token() == Token.ORDER) {
        SQLOrderBy orderBy = this.parseOrderBy();
        aggregateExpr.putAttribute("ORDER BY", orderBy);
    }
    if (identifierEquals("SEPARATOR")) {
        lexer.nextToken();
        SQLExpr seperator = this.primary();
        aggregateExpr.putAttribute("SEPARATOR", seperator);
    }
    return aggregateExpr;
}
Also used : SQLOrderBy(com.alibaba.druid.sql.ast.SQLOrderBy) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr)

Example 47 with SQLExpr

use of com.alibaba.druid.sql.ast.SQLExpr in project druid by alibaba.

the class DB2SelectParser method query.

@Override
public SQLSelectQuery query() {
    if (lexer.token() == Token.LPAREN) {
        lexer.nextToken();
        SQLSelectQuery select = query();
        accept(Token.RPAREN);
        return queryRest(select);
    }
    accept(Token.SELECT);
    if (lexer.token() == Token.COMMENT) {
        lexer.nextToken();
    }
    DB2SelectQueryBlock queryBlock = new DB2SelectQueryBlock();
    if (lexer.token() == Token.DISTINCT) {
        queryBlock.setDistionOption(SQLSetQuantifier.DISTINCT);
        lexer.nextToken();
    } else if (lexer.token() == Token.UNIQUE) {
        queryBlock.setDistionOption(SQLSetQuantifier.UNIQUE);
        lexer.nextToken();
    } else if (lexer.token() == Token.ALL) {
        queryBlock.setDistionOption(SQLSetQuantifier.ALL);
        lexer.nextToken();
    }
    parseSelectList(queryBlock);
    parseFrom(queryBlock);
    parseWhere(queryBlock);
    parseGroupBy(queryBlock);
    if (lexer.token() == Token.ORDER) {
        SQLOrderBy orderBy = parseOrderBy();
        queryBlock.setOrderBy(orderBy);
    }
    for (; ; ) {
        if (lexer.token() == Token.FETCH) {
            lexer.nextToken();
            accept(Token.FIRST);
            SQLExpr first = this.exprParser.primary();
            queryBlock.setFirst(first);
            if (identifierEquals("ROW") || identifierEquals("ROWS")) {
                lexer.nextToken();
            }
            accept(Token.ONLY);
            continue;
        }
        if (lexer.token() == Token.WITH) {
            lexer.nextToken();
            if (identifierEquals("RR")) {
                queryBlock.setIsolation(Isolation.RR);
            } else if (identifierEquals("RS")) {
                queryBlock.setIsolation(Isolation.RS);
            } else if (identifierEquals("CS")) {
                queryBlock.setIsolation(Isolation.CS);
            } else if (identifierEquals("UR")) {
                queryBlock.setIsolation(Isolation.UR);
            } else {
                throw new ParserException("TODO");
            }
            lexer.nextToken();
            continue;
        }
        if (lexer.token() == Token.FOR) {
            lexer.nextToken();
            if (lexer.token() == Token.UPDATE) {
                queryBlock.setForUpdate(true);
                lexer.nextToken();
            } else {
                acceptIdentifier("READ");
                accept(Token.ONLY);
                queryBlock.setForReadOnly(true);
            }
        }
        if (lexer.token() == Token.OPTIMIZE) {
            lexer.nextToken();
            accept(Token.FOR);
            queryBlock.setOptimizeFor(this.expr());
            if (identifierEquals("ROW")) {
                lexer.nextToken();
            } else {
                acceptIdentifier("ROWS");
            }
        }
        break;
    }
    return queryRest(queryBlock);
}
Also used : ParserException(com.alibaba.druid.sql.parser.ParserException) SQLOrderBy(com.alibaba.druid.sql.ast.SQLOrderBy) SQLSelectQuery(com.alibaba.druid.sql.ast.statement.SQLSelectQuery) DB2SelectQueryBlock(com.alibaba.druid.sql.dialect.db2.ast.stmt.DB2SelectQueryBlock) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr)

Example 48 with SQLExpr

use of com.alibaba.druid.sql.ast.SQLExpr in project druid by alibaba.

the class SQLDeleteBuilderImpl method whereAnd.

@Override
public SQLDeleteBuilder whereAnd(String expr) {
    SQLDeleteStatement delete = getSQLDeleteStatement();
    SQLExpr exprObj = SQLUtils.toSQLExpr(expr, dbType);
    SQLExpr newCondition = SQLUtils.buildCondition(SQLBinaryOperator.BooleanAnd, exprObj, false, delete.getWhere());
    delete.setWhere(newCondition);
    return this;
}
Also used : SQLDeleteStatement(com.alibaba.druid.sql.ast.statement.SQLDeleteStatement) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr)

Example 49 with SQLExpr

use of com.alibaba.druid.sql.ast.SQLExpr in project druid by alibaba.

the class SQLSelectBuilderImpl method groupBy.

@Override
public SQLSelectBuilderImpl groupBy(String expr) {
    SQLSelectQueryBlock queryBlock = getQueryBlock();
    SQLSelectGroupByClause groupBy = queryBlock.getGroupBy();
    if (groupBy == null) {
        groupBy = createGroupBy();
        queryBlock.setGroupBy(groupBy);
    }
    SQLExpr exprObj = SQLUtils.toSQLExpr(expr, dbType);
    groupBy.addItem(exprObj);
    return this;
}
Also used : SQLSelectGroupByClause(com.alibaba.druid.sql.ast.statement.SQLSelectGroupByClause) SQLSelectQueryBlock(com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr)

Example 50 with SQLExpr

use of com.alibaba.druid.sql.ast.SQLExpr in project druid by alibaba.

the class SQLSelectBuilderImpl method having.

@Override
public SQLSelectBuilderImpl having(String expr) {
    SQLSelectQueryBlock queryBlock = getQueryBlock();
    SQLSelectGroupByClause groupBy = queryBlock.getGroupBy();
    if (groupBy == null) {
        groupBy = createGroupBy();
        queryBlock.setGroupBy(groupBy);
    }
    SQLExpr exprObj = SQLUtils.toSQLExpr(expr, dbType);
    groupBy.setHaving(exprObj);
    return this;
}
Also used : SQLSelectGroupByClause(com.alibaba.druid.sql.ast.statement.SQLSelectGroupByClause) SQLSelectQueryBlock(com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr)

Aggregations

SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)225 SQLIdentifierExpr (com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr)42 SQLName (com.alibaba.druid.sql.ast.SQLName)33 SQLBinaryOpExpr (com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr)30 ParserException (com.alibaba.druid.sql.parser.ParserException)23 SQLObject (com.alibaba.druid.sql.ast.SQLObject)22 SQLPropertyExpr (com.alibaba.druid.sql.ast.expr.SQLPropertyExpr)17 SQLIntegerExpr (com.alibaba.druid.sql.ast.expr.SQLIntegerExpr)16 SQLCharExpr (com.alibaba.druid.sql.ast.expr.SQLCharExpr)13 SQLSelectQueryBlock (com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock)13 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)12 ArrayList (java.util.ArrayList)12 SQLVariantRefExpr (com.alibaba.druid.sql.ast.expr.SQLVariantRefExpr)11 SQLMethodInvokeExpr (com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr)10 SQLSelectItem (com.alibaba.druid.sql.ast.statement.SQLSelectItem)10 SQLSelectQuery (com.alibaba.druid.sql.ast.statement.SQLSelectQuery)10 SQLOrderBy (com.alibaba.druid.sql.ast.SQLOrderBy)8 MySqlSelectQueryBlock (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock)8 SQLNumberExpr (com.alibaba.druid.sql.ast.expr.SQLNumberExpr)7 SQLExprTableSource (com.alibaba.druid.sql.ast.statement.SQLExprTableSource)7